﻿#include "stdafx.h"
#include "scriptMaple.h"
#include "thread_control.h"
#include "script.h"
#include "GameDlg.h"
#include "ScriptWls.h"

//背包整理
bool ZhengLi(long index, int taskIndex) {
	long x, y;
	CDm *dm = g_info[index].dm;
	dm->RunScript(L"背包线", &x, &y);
	CString str;
	str.Format(L"背包坐标%d", x);
	g_main_cwnd->AppendText(str);
	if (x > 0) {
		str.Format(L"开始整理");
		g_main_cwnd->AppendText(str);
		//点击装备栏
		dm->MoveTo(x+10+RandomNumber(1,10), y+5+RandomNumber(1,5));
		Sleep(RandomNumber(100, 300));
		dm->LeftClick();
		Sleep(RandomNumber(500, 1000));
		dm->RunScript(L"整理");
		Sleep(RandomNumber(1000, 1500));

		dm->MoveTo(x+42 + RandomNumber(1, 10), y + 5 + RandomNumber(1, 5));
		Sleep(RandomNumber(100, 300));
		dm->LeftClick();
		Sleep(RandomNumber(500, 1000));
		dm->RunScript(L"整理");
		Sleep(RandomNumber(1000, 1500));
		
		if (dm->RunScript(L"背包消耗武器")) {

			int nIndex = g_AccountFile.GetInt(NumberToString(taskIndex + 1), L"RoleNum");
			CString strIndex = NumberToString(++nIndex);
			CString strBu = g_AccountFile.GetString(NumberToString(taskIndex + 1), L"Bu");
			if (strBu == L"") {
				g_AccountFile.SetString(NumberToString(taskIndex + 1), L"Bu", L"." + strIndex + L".");
			}
			strBu = g_AccountFile.GetString(NumberToString(taskIndex + 1), L"Bu");
			if (strBu.Find(L"." + strIndex + L".") == -1) {//
				g_AccountFile.SetString(NumberToString(taskIndex + 1), L"Bu", strBu + strIndex + L".");
			}
		}

		dm->MoveTo(x+75 + RandomNumber(1, 10), y + 5 + RandomNumber(1, 5));
		Sleep(RandomNumber(100, 300));
		dm->LeftClick();
		Sleep(RandomNumber(500, 1000));
		dm->RunScript(L"整理");
		Sleep(RandomNumber(1000, 1500));
		dm->MoveTo(x+ RandomNumber(400, 500), y + RandomNumber(100, 500));
		
	}
	str.Format(L"整理结束");
	g_main_cwnd->AppendText(str);
	return true;
}

bool BuZhuang(long index, int taskIndex,CString strWuPin) {
	long x, y;
	CDm *dm = g_info[index].dm;
	g_main_cwnd->AppendText(L"补充开始");
	for (size_t i = 0; i < 1; i++)
	{
		dm->RunScript(L"材料商人");
		g_main_cwnd->AppendText(L"找到npc材料商人");
		//买卖窗口是否打开
		//if (!dm->RunScript(L"买卖窗口")) {
		//	dm->RunScript(L"材料商人");
		//}
		Sleep(RandomNumber(500, 1000));
		if (dm->RunScript(L"买卖窗口", &x, &y)) {
			//点击消耗栏
			dm->Click(x+202, y+93, 10, 5);
			Sleep(RandomNumber(500, 1000));
			if (dm->RunScript(L"选中消耗")) {
				if (strWuPin == L"bagBiao.bmp" || strWuPin == L"bagDan.bmp") {
					g_main_cwnd->AppendText(L"补充开始");
					int k = 0;
					for (size_t i = 0; i < 5; i++)
					{
						if (dm->RunScript(L"补充按钮")) {
							Sleep(RandomNumber(500, 1000));
							dm->KeyPressChar(L"enter");
							Sleep(RandomNumber(500, 1000));
							k++;
						}
					}
					if (k > 0) {
						if (dm->RunScript(L"确定")) {
							Sleep(RandomNumber(500, 1000));
							dm->KeyPressChar(L"enter");
							Sleep(RandomNumber(500, 1000));
						}
						if (dm->RunScript(L"买卖窗口", &x, &y)) {
							Sleep(RandomNumber(500, 1000));
							dm->Click(x + 100, y + 45, 20, 5);
						}
						return true;
					}
				}
				if (strWuPin == L"buJian.bmp" || strWuPin == L"buJian1.bmp") {
					//dm->MoveTo(x+130, y+124);
					//dm->LeftDown();
					//dm->MoveTo(x+130, y+224);
					//dm->LeftUp();
					////dm->Click(x + 10, y + 193, 10, 15);
					//dm->MiddleDown();
					dm->MoveTo(x + 10+RandomNumber(1,5), y + 193 + RandomNumber(1, 15));
					for (size_t i = 0; i < 18; i++)
					{
						dm->WheelDown();
						Sleep(RandomNumber(100, 250));
					}
					Sleep(RandomNumber(1000, 2500));
					CString strJian = strWuPin == L"buJian.bmp" ? L"shopjian.bmp" : L"shopjian1.bmp";
					dm->FindPic(10, 10, 800, 700, strJian, L"050505", 0.9, 0,&x,&y);
					if (x > 0) {
						dm->Click(x+5, y + 5, 10, 5);
						dm->LeftClick();
						Sleep(RandomNumber(2000, 2550));
						//dm->KeyPressChar(L"enter");
						//dm->KeyDownChar(L"enter");
						//
						dm->KeyPressChar(L"enter");
						Sleep(RandomNumber(500, 1000));
						//dm->KeyUpChar(L"enter");
					}
					if (dm->RunScript(L"确定", &x, &y)) {
						/*dm->Click(x + 5, y + 5, 20, 5);
						Sleep(RandomNumber(500, 1000));*/
						dm->KeyPressChar(L"enter");
						Sleep(RandomNumber(500, 1000));
					}
					dm->FindPic(482, 228, 800, 647, strWuPin, L"050505", 0.9, 0, &x, &y);
					if (x > 0) {
						
						if (dm->RunScript(L"买卖窗口", &x, &y)) {
							Sleep(RandomNumber(500, 1000));
							dm->Click(x + 100, y + 45, 20, 5);
						}
						return true;
					}

					//dm->MiddleUp();
				
				}
			}
		}
	}
	if (dm->RunScript(L"确定", &x, &y)) {
		/*dm->Click(x + 5, y + 5, 20, 5);
		Sleep(RandomNumber(500, 1000));*/
		dm->KeyPressChar(L"enter");
		Sleep(RandomNumber(500, 1000));
	}
	if (dm->RunScript(L"买卖窗口", &x, &y)) {
		Sleep(RandomNumber(500, 1000));
		dm->Click(x + 100, y + 45, 20, 5);
	}
	return true;
}

bool ZkYouPiao(long index, int taskIndex) {
	long x, y, x1, y1;
	CDm *dm = g_info[index].dm;
	bool bDrop = false;
	dm->UseDict(0);
	for (size_t i = 0; i < 10; i++)
	{
		//1.按键n
		//Sleep(RandomNumber(500, 1000));
		if (dm->RunScript(L"猎人窗口", &x, &y)) {
			//是否选中商店栏目n
			if (dm->RunScript(L"猎人商店栏目")) {
				//long x1, y1;
				if (dm->RunScript(L"确定", &x1, &y1)) {

					//识别数字
					CString strNum = dm->Ocr(x1, y1 - 70, x1 + 100, y1, L"ffffff", 1);
					if (strNum == L"" || strNum == L"0") {
						Sleep(RandomNumber(500, 1000));
						if (dm->RunScript(L"确定")) {
							dm->KeyPress(27);
						}
						Sleep(RandomNumber(500, 1000));
						if (dm->RunScript(L"猎人窗口")) {
							dm->KeyPress(27);
						}
						return true;
					}
					dm->SendString2(dm->GetBindWindow(), strNum);
					Sleep(RandomNumber(500, 1000));
					dm->KeyPress(13);
					Sleep(RandomNumber(1500, 2000));
					if (dm->RunScript(L"确定")) {
						dm->KeyPress(13);
						Sleep(RandomNumber(1500, 2000));
						return true;
					}

				}
				else {
					dm->Click(x, y + 56, 30, 5);
					Sleep(RandomNumber(80, 150));
					dm->LeftClick();
					Sleep(RandomNumber(500, 1000));
				}
			}
			else {
				dm->Click(x + 152, y + 25, 10, 3);
				Sleep(RandomNumber(500, 1000));
			}
		}
		else {
			dm->KeyPressChar(L"n");
			Sleep(RandomNumber(500, 1000));
			if (!dm->RunScript(L"猎人窗口")) {//未打卡十字猎人窗口
				for (size_t k = 0; k < 10; k++)
				{
					if (dm->RunScript(L"猎人N快捷键")) {
						dm->RunScript(L"快捷键确认");
						break;
					}


					if (dm->RunScript(L"初始化快捷键", &x, &y))//是否打开快捷键窗口
					{
						//+235 -247
						//long x1, y1;
						if (dm->RunScript(L"猎人按钮", &x1, &y1)) {
							//if (y1 > y - 177) {//猎人按钮未设定快捷键
							//	
							//}
							dm->Click(x1 + 5, y1 - 5, 5, 5);
							Sleep(RandomNumber(1000, 2000));
							dm->MoveToEx(x + 245, y - 237, 5, 5);
							Sleep(RandomNumber(1000, 2000));
							dm->LeftClick();
							Sleep(RandomNumber(500, 2000));
							dm->MoveToEx(5, 5, 200, 500);
						}
					}
					else {//未打开快捷键窗口执行快捷键窗口
						if (dm->RunScript(L"设置", &x, &y)) {//设置是否打开
							dm->Click(x + 10, y + 117, 10, 5);
							Sleep(RandomNumber(1000, 2000));
						}
						else {
							dm->KeyPressChar(L"esc");
						}
					}
				}
			}
		}
	}

	return true;
}

bool WlsYouPiao(long index, int taskIndex) {
	//1.是否在乌鲁斯地图
	//2.查找npc 位置
	CString strList = L"关闭广告|关闭广告1|登录确定";
	long x, y;
	CDm *dm = g_info[index].dm;
	bool bDrop = false;
	while (true) {
		RunScriptList(index, strList);
		//关闭组队
		CloseTearm(index);
		//位置在交易地图则退出交易地图
		if (dm->RunScript(L"交易地图")) {
			dm->KeyPressChar(L"up");
		}
		//执行进入wls操作
		if (dm->RunScript(L"冰峰雪域地图") || dm->RunScript(L"导航按钮")) {
			ChoseBoss(index, L"选中乌鲁斯", 92, 260);//选择乌鲁斯
		}
		//退出扎昆
		ExitZkjt(index);
		ExitZkrk(index);

		//材料窗口是否打开
		if (dm->RunScript(L"乌鲁斯材料窗口")) {
			for (size_t i = 0; i < 100; i++)
			{

				Sleep(RandomNumber(500, 1000));
				/*dm->RunScript(L"乌鲁斯材料窗口");
				Sleep(RandomNumber(500, 1000));*/
				dm->RunScript(L"乌鲁斯换取");
				Sleep(RandomNumber(500, 1000));
				if (dm->RunScript(L"确定")) {
					dm->KeyPressChar(L"enter");
					Sleep(RandomNumber(1500, 2000));
					//for (size_t j = 0; j < 20; j++)
					//{
					//	if (!dm->RunScript(L"确定")) {
					//		break;
					//	}
					//	else {
					//		dm->KeyPressChar(L"enter");
					//	}
					//	Sleep(RandomNumber(50, 100));
					//}

				}

				//if (dm->RunScript(L"背包满")) {
				//	if (dm->RunScript(L"下一步1")) {
				//		//dm->KeyPressChar(L"enter");
				//		dm->KeyPress(32);
				//		Sleep(RandomNumber(1500, 2000));
				//	}
				//	for (size_t k = 0; k < 100; k++)
				//	{
				//		//如果卡片不存在快捷栏
				//		if (!dm->RunScript(L"快捷卡片")) {
				//			dm->KeyPressChar(L"i");
				//			Sleep(RandomNumber(1500, 2000));
				//			if (dm->RunScript(L"背包线")) {
				//				if (dm->RunScript(L"邮票卡片",&x,&y)) {
				//					//dm->Click(x, y, 10, 5);
				//					dm->MoveToEx(x, y, 10, 5);
				//					Sleep(RandomNumber(1500, 2000));
				//					dm->LeftClick();
				//					Sleep(RandomNumber(1500, 2000));
				//					dm->MoveTo(926 + RandomNumber(1, 5), 698 + RandomNumber(5, 10));
				//					
				//					dm->LeftDoubleClick();
				//					//Sleep(RandomNumber(1500, 2000));
				//					//dm->MoveTo(726 + RandomNumber(5, 80), 698 + RandomNumber(5, 10));
				//					//Sleep(RandomNumber(1500, 2000));
				//					//dm->LeftClick();
				//					//Sleep(RandomNumber(1500, 2000));
				//					if (dm->RunScript(L"背包线")) {
				//						dm->KeyPressChar(L"i");
				//					}
				//					Sleep(RandomNumber(1500, 2000));
				//				}
				//			}
				//		}
				//		else
				//		{
				//			dm->KeyPress(45);
				//			Sleep(RandomNumber(1500, 2000));
				//			//break;
				//			//找到卡片 是否
				//		}


				if (dm->RunScript(L"乌鲁斯邮票结束")) {
					for (size_t j = 0; j < 6; j++)
					{
						dm->RunScript(L"快捷卡片");
						if (dm->RunScript(L"下一步1")) {
							//dm->KeyPressChar(L"enter");
							dm->KeyPress(32);
							Sleep(RandomNumber(1500, 2000));
						}
					}

					g_main_cwnd->m_list_info.SetItemText(taskIndex, 6, L"完成");//当前账号置完成
					taskIndex = taskIndex + 1;
					g_AccountFile.SetString(NumberToString(taskIndex), L"state", L"1");
					int nLineCode = g_IniFile.GetInt(L"Set", L"CodeLine");//当前配置线路
					int nLineCode1 = _wtoi(g_main_cwnd->m_list_info.GetItemText(taskIndex, 12));
					if (nLineCode == nLineCode1) {
						//切换角色
						bDrop = false;
						SwicthRole(index, taskIndex);
						break;
					}
					else {
						bDrop = false;
						return true;
					}
					//关闭窗口
				}
				if (dm->RunScript(L"下一步1")) {
					//dm->KeyPressChar(L"enter");
					dm->KeyPress(32);
					for (size_t j = 0; j < 10; j++)
					{
						if (!dm->RunScript(L"下一步1")) {
							Sleep(RandomNumber(500, 1000));
							break;
						}
						Sleep(RandomNumber(50, 100));
					}
					if (!bDrop) {//首次检查快捷蓝是否存在邮票
						for (size_t k = 0; k < 5; k++)
						{
							if (!dm->RunScript(L"快捷卡片")) {
								dm->KeyPressChar(L"i");
								Sleep(RandomNumber(1500, 2000));
								if (dm->RunScript(L"背包线", &x, &y)) {
									dm->Click(x + 41, y + 3, 5, 5);
									Sleep(RandomNumber(1500, 2000));
									if (dm->RunScript(L"邮票卡片", &x, &y)) {
										//dm->Click(x, y, 10, 5);
										dm->MoveToEx(x, y, 10, 5);
										Sleep(RandomNumber(1500, 2000));
										dm->LeftClick();
										Sleep(RandomNumber(1500, 2000));
										dm->MoveTo(890 + RandomNumber(1, 20), 698 + RandomNumber(5, 10));
										Sleep(RandomNumber(1500, 2000));
										dm->LeftDoubleClick();
										Sleep(RandomNumber(1500, 2000));
										dm->MoveTo(790 + RandomNumber(5, 50), 698 + RandomNumber(5, 10));
										Sleep(RandomNumber(1500, 2000));
										if (dm->RunScript(L"背包线")) {
											dm->KeyPressChar(L"i");
										}
									}
								}
							}
							else
							{
								bDrop = true;
								break;
								//找到卡片 是否
							}
						}
					}


				}


				if (!dm->RunScript(L"快捷邮票0")) {
					if (dm->RunScript(L"快捷卡片")) {
						dm->KeyPress(45);
						Sleep(RandomNumber(500, 800));
						if (!dm->RunScript(L"快捷邮票0")) {
							dm->KeyPress(45);
							Sleep(RandomNumber(200, 300));
						}
					}
				}



			}
		}
		else {
			dm->RunScript(L"npc乌鲁斯材料");
			Sleep(RandomNumber(500, 1000));
			for (size_t i = 0; i < 5; i++)
			{
				if (dm->RunScript(L"下一步1")) {
					//dm->KeyPressChar(L"enter");
					dm->KeyPress(32);
					Sleep(RandomNumber(1500, 2000));
				}
			}

		}
		//Sleep(RandomNumber(500, 1000));
	}
	return true;

}



bool SwitchRoles(long index, int taskIndex) {
	dmsoft *dm = g_info[index].dm;
	long x, y,x1,y1;
	bool flag = false;
	int a = g_AccountFile.GetInt(NumberToString(taskIndex + 1), L"RoleNum");
	CString str;
	for (size_t i = 0; i < 10; i++)
	{
		//是否到达选择角色页面
		if (!flag) {
			str.Format(L"执行切换角色第%d次", i);
			g_main_cwnd->AppendText(str);

			dm->FindPic(1, 0, 210, 52, L"RoleWnd.bmp", L"303030", 0.9, 0, &x, &y);
			if (x > 0) {//登录到游戏角色页面
				CString strPage;
				if (a <8) {// 第一页
					strPage = L"page1.bmp";
				}
				if (a >= 8 && a < 17) {//2
					strPage = L"page2.bmp";
				}
				if (a >= 16 && a < 25) {//3
					strPage = L"page3.bmp";
				}
				if (a >= 24 && a < 33) {//4
					strPage = L"page4.bmp";
				}
				if (a >= 32 && a < 41) {//5
					strPage = L"page5.bmp";
				}
				if (a >= 40 && a < 49) {//6
					strPage = L"page6.bmp";
				}
				if (a >= 48 && a < 57) {//7
					strPage = L"page7.bmp";
				}
				if (a >=8) {
					if (a % 8 == 0) {
						a = 0;
					}
					else {
						a = a % 8;
					}
				}
				long x1, y1;
				for (size_t k = 0; k < 5; k++)
				{
					dm->FindPic(251, 454, 380, 492, strPage, L"050505", 1, 0, &x, &y);
					//如果第一个存在
					if (x > 0) {
						dm->FindPic(183, 137, 635, 207, L"twoCodeWnd2.bmp", L"050505", 1, 0, &x1, &y1);
						if (x1 > 0)
						{
							break;
						}
						dm->MoveTo(g_Point[a][0], g_Point[a][1]);
						dm->LeftDoubleClick();
						Sleep(RandomNumber(1000, 2000));
					}
					else {
						dm->MoveToEx(500, 515, 10, 5);
						Sleep(RandomNumber(100, 200));
						dm->LeftClick();
						Sleep(RandomNumber(1000, 2000));
					}
				}


				//二密窗口显示，首次进入
				dm->FindPic(183, 137, 635, 207, L"twoCodeWnd2.bmp", L"050505", 1, 0, &x1, &y1);
				if (x > 0 && !flag) {
					CString str = g_main_cwnd->m_list_info.GetItemText(taskIndex, 3);
					CString code;
					for (int i = 0; i < str.GetLength(); i++)
					{
						//code1 = code1 + code.Mid(i, 1);
						CString strbmp = str.Mid(i, 1) + L".bmp";
						//CString sTwoCode = L"输入二密" + code.Mid(i, 1);
						if (i == str.GetLength() - 1) {
							code += strbmp;
						}
						else {
							code += strbmp + L"|";
						}
					}
					CString strKeyCode = dm->FindPicExS(126, 222, 675, 417, code, L"202020", 0.90, 0);
					CStringArray arr;
					StringSplit(strKeyCode, arr, '|');

					for (size_t i = 0; i < 5; i++)
					{
						if (str.GetLength() == arr.GetCount()) {
							break;
						}
						else {
							dm->MoveTo(RandomNumber(100, 200), RandomNumber(10, 20));
							Sleep(100);
							strKeyCode = dm->FindPicExS(126, 222, 675, 417, code, L"202020", 0.90, 0);
							StringSplit(strKeyCode, arr, '|');
							Sleep(100);
						}
					}


					for (size_t i = 0; i < arr.GetCount(); i++)
					{
						CStringArray arr1;
						StringSplit(arr.GetAt(i), arr1, ',');
						dm->MoveTo(_wtoi(arr1.GetAt(1)) + RandomNumber(5, 10), _wtoi(arr1.GetAt(2)) + RandomNumber(15, 20));
						Sleep(RandomNumber(1500, 1600));
						dm->LeftClick();
						Sleep(RandomNumber(150, 200));
						//识别密码个数星星

						CString strPwd = dm->FindPicEx(302, 193, 505, 229, L"pwdxing.bmp", L"000000", 1, 0);
						int nCount = strPwd.Replace(L"|", L"|");
						if (strPwd == "") {
							i = -1;
							continue;
						}
						else if (i != nCount) {
							i--;
						}

					}
					for (int i = 0; i < 5; i++)
					{
						dm->FindPic(298, 415, 399, 441, L"enterCode.bmp", L"303030", 0.85, 0, &x, &y);
						if (x > 0) {
							dm->MoveToEx(x, y, 10, 5);
							dm->LeftClick();
							dm->delay(RandomNumber(8000, 10000));
							flag = true;
							break;
						}
					}
				}

				dm->FindPic(281, 213, 524, 350, L"twoCodeError.bmp", L"303030", 0.9, 0, &x, &y);
				if (x > 0) {
					//TODO: 二密错误 处理 
					g_AccountFile.SetString(NumberToString(taskIndex + 1), L"state", L"3");
					g_main_cwnd->m_list_info.SetItemText(taskIndex, 6, L"二密错误");
					KillProcess(L"MapleStory.exe");
					ScriptDelay(index, 1000);
					g_flag = false;
					return false;
				}
			}
			else {
				Sleep(1000);
				//dm->FindPic(0, 0, 510, 400, L"mapB.bmp", L"050505", 1, 0, &x, &y);
				dm->FindPic(407, 657, 845, 762, L"loginSuccess.bmp|loginSuccess1.bmp|loginSuccess2.bmp", L"202020", 0.9, 0, &x, &y);
				if (x > 0) {
					str.Format(L"游戏页面执行退出", i);
					g_main_cwnd->AppendText(str);
					//if (x > 0) {
					dm->FindPic(708, 526, 856, 581, L"setting.bmp", L"050505",1, 0, &x, &y);
					str.Format(L"配置坐标%d", x);
					g_main_cwnd->AppendText(str);
					if (x == -1) {
						dm->KeyPress(27);
						Sleep(RandomNumber(500, 1300));
					}
					else {
						dm->MoveToEx(x + 20, y + 145, 10, 3);
						Sleep(RandomNumber(200, 300));
						dm->LeftClick();
						Sleep(RandomNumber(2200, 3300));
					}
					dm->FindPic(0, 0, 800, 600, L"okWnd.bmp|okWnd1.bmp|okWnd2.bmp", L"101010", 0.9, 0, &x, &y);
					if (x > 0) {
						dm->KeyPress(13);
						Sleep(RandomNumber(200, 300));
					}
					dm->FindPic(364, 403, 633, 624, L"gameOut.bmp", L"202020", 0.8, 0, &x, &y);
					if (x > 0) {
						dm->MoveTo(x + 3, y + 3);
						Sleep(RandomNumber(200, 300));
						dm->LeftClick();
						Sleep(RandomNumber(2200, 3300));
					}

				}
			}
			dm->FindPic(1, 0, 210, 52, L"serverWnd.bmp", L"303030", 0.9, 0, &x, &y);
			if (x > 0) {
				dm->KeyPress(13);
				Sleep(RandomNumber(1200, 1300));
				if (runScript(index, L"loginServer25")) {
					ScriptDelay(index, 1000);
					dm->KeyPress(13);
				}
			}


		}
		else
		{
			Sleep(1000);
			//选择角色登录
			//判定是否登录到游戏
			dm->FindPic(407, 657, 845, 762, L"loginSuccess.bmp|loginSuccess1.bmp|loginSuccess2.bmp", L"303030", 0.9, 0, &x, &y);
			if (x > 0) {
				str.Format(L"进入游戏页面%d", i);
				g_main_cwnd->AppendText(str);
				g_nState = 0;
				return true;
			}
		}
		Sleep(2500);
	}
	return false;
}

bool SwitchCode(long index, int taskIndex) {

	long x, y;
	dmsoft *dm = g_info[index].dm;
	CString taskStr = L"loginOkWnd|closeWnd|closeWnd1|closeWnd4";
	runScriptList(index, taskStr);
	for (size_t i = 0; i < 10; i++)
	{
		dm->FindPic(0, 0, 1024, 700, L"next.bmp", L"050505", 1, 0, &x, &y);
		if (x > 0) {
			dm->KeyPress(32);
			ScriptDelay(index, 1000);
		}
		dm->FindStrFast(771, 722, 799, 751, L"config", L"b@e2eef3-202020", 0.85, &x, &y);
		if (x > 0) {
			dm->MoveTo(x + 3, y + 3);
			dm->LeftClick();

			ScriptDelay(index,1000);
			dm->MoveTo(x + 3, y - 35);
			dm->LeftClick();
			ScriptDelay(index,2000);

		}
		dm->FindPic(364, 403, 633, 624, L"gameOut.bmp", L"202020", 0.8, 0, &x, &y);
		if (x > 0) {
			dm->MoveTo(x + 3, y + 3);
			dm->LeftClick();
			ScriptDelay(index,1000);
		}
		dm->FindPic(2, 509, 96, 553, L"gameOut1.bmp", L"202020", 0.8, 0, &x, &y);
		if (x > 0) {
			dm->MoveTo(x + 3, y + 3);
			dm->LeftClick();
			ScriptDelay(index,1000);
		}
		dm->FindPic(274, 220, 528, 347, L"gameOut2.bmp", L"202020", 0.8, 0, &x, &y);
		if (x > 0) {
			dm->MoveTo(x + 10, y + 15);
			dm->LeftClick();
			ScriptDelay(index,1000);
		}

		ScriptDelay(index,1000);
	}
	for (int i = 0; i < 5; i++)
	{
		dm->FindPic(0, 0, 800, 600, L"gameLogo.bmp|code.bmp|password.bmp", L"050505", 0.95, 0, &x, &y);
		if (x > 0) {
			//OutPutListView(nIndex, L"游戏登录成功");
			return true;
		}
	}
	return true;
}

bool StartLoginClient(long index, int taskIndex) {//启动客户端
	g_main_cwnd->AppendText(L"启动游戏客户端");
	dmsoft *dm = g_info[index].dm;
	int state = 0;
	int hwnd = 0;
	int ret = 0;
	int j = 0;
	long x, y;
	while (g_flag)
	{
		
		if (state == 0) {
			CheckState = false;
			if (dm->GetBindWindow() > 0) {
				dm->UnBindWindow();
			}
			dm->MoveTo(0, 1);
			dm->LeftClick();
			g_main_cwnd->AppendText(L"打开游戏");
			hwnd = dm->FindWindow(L"MapleStoryClass", L"MapleStory");
			if (hwnd  !=0) {
				KillProcess(L"MapleStory.exe");
				//dm->TerminateProcess()
				ScriptDelay(index, 1000);
			}
			ScriptDelay(index, 100);
			hwnd = dm->FindWindow(L"", L"MapleStory");
			for (size_t i = 0; i < 5; i++)
			{
				dm->FindPic(0, 0, 500, 960, L"game.bmp", L"202020", 0.8, 0, &x, &y);
				CString str;
				
				str.Format(L"游戏图标坐标%d,%d,%d", x, y, dm->GetBindWindow());
				g_main_cwnd->AppendText(str);
				if (x > 0) {
					dm->MoveTo(x, y);
					dm->LeftDoubleClick();
					break;
				}
				Sleep(1000);
			}
			ScriptDelay(index,1000);
			hwnd = dm->FindWindow(L"", L"MapleStory");//查找客户端句柄
			dm->SetWindowState(hwnd, 12);
			ScriptDelay(index,1000);
			dm->KeyPress(9);
			ScriptDelay(index, 1000);
			dm->KeyPress(13);
			ScriptDelay(index, 20000);
			dm->MoveTo(0, 1);
			dm->LeftClick();

			for (int i = 0; i < 10; i++)
			{
				
				hwnd = dm->FindWindow(L"MapleStoryClass", L"MapleStory");
				if (hwnd !=0) {
					g_main_cwnd->AppendText(L"游戏开启成功");
					g_main_cwnd->AppendText(L"游戏句柄:" + NumberToString(hwnd));
					state = 1;
					ScriptDelay(index, 10000);
					break;
				}
				g_main_cwnd->AppendText(L"游戏句柄:"+NumberToString(hwnd));
				ScriptDelay(index, 15000);
			}
			
		}
		else if(state==1)
		{
			//hwnd = dm->FindWindow(L"", L"MapleStory");//查找客户端句柄
			//if (hwnd > 0) {
			//	//state = 1;
			//}
			//查找登录窗口
			g_main_cwnd->AppendText(L"查找游戏窗口");
			hwnd = dm->FindWindow(L"MapleStoryClass", L"MapleStory");
			g_main_cwnd->AppendText(L"游戏句柄:" + NumberToString(hwnd));
			if (hwnd != 0 && ret==0) {
				 ret = g_info[index].dm->BindWindowEx(hwnd, L"normal", L"normal", L"normal", L"", 0);
				 g_main_cwnd->AppendText(L"绑定游戏句柄:" + NumberToString(ret));
				 g_info[index].hwnd = hwnd;
				 CheckState = true;//开启窗口监控
			}
			if (ret == 1) {
				ScriptDelay(index, 3000);
				if (runScript(index, L"LoginYes")) {
					ScriptDelay(index, 3000);
					//设置监控状态
					return true;
				}
			}
			if (j > 150) {
				j = 0;
				state = 0;
			}
			j++;
		}
		
		ScriptDelay(index, 1000);
		//开启客户端之前先关闭已开启的客户端
	}
	return true;
}

bool StartLoginGameZhaKun(long index, int taskIndex, bool flagLogin) {
	VARIANT x, y;
	bool flag = false;
	dmsoft *dm = g_info[index].dm;
	dm->MoveWindow(g_info[index].hwnd, 0, 0);
	dm->UseDict(1);
	while (g_flag)
	{
		
		//如果登录当前刷完的次数跟所有角色相等则返回假
		if (g_main_cwnd->m_list_info.GetItemText(taskIndex, 7) == g_main_cwnd->m_list_info.GetItemText(taskIndex, 10)) {
			g_AccountFile.SetString(NumberToString(taskIndex + 1), L"state", L"1");
			g_main_cwnd->m_list_info.SetItemText(taskIndex, 6, L"完成");
			return false;
		}
		long hwnd = dm->FindWindow(L"MapleStoryClass", L"MapleStory");
		if (hwnd == 0) {//窗口不存在返回假
			return false;
		}
		CString strSs;
		strSs.Format(L"开始登录", g_main_cwnd->m_list_info.GetItemText(taskIndex, 4));
		g_main_cwnd->AppendText(strSs);

		//账号
		dm->FindPic(288, 220, 510, 301, L"onLineCode.bmp", L"202020", 0.8, 0, &x.lVal, &y.lVal);
		if (x.lVal > 0) {
			g_AccountFile.SetString(NumberToString(taskIndex + 1), L"state", L"5");
			g_main_cwnd->m_list_info.SetItemText(taskIndex, 6, L"账号在线");
			KillProcess(L"MapleStory.exe");
			ScriptDelay(index, 1000);
			return false;
		}
		if (runScript(index, L"codeError") || runScript(index, L"codeError1")) {
			g_AccountFile.SetString(NumberToString(taskIndex + 1), L"state", L"2");
			g_main_cwnd->m_list_info.SetItemText(taskIndex, 6, L"账号错误");
			KillProcess(L"MapleStory.exe");
			ScriptDelay(index, 1000);
			return false;
		}
		if (runScript(index, L"twoPwdError")) {
			g_AccountFile.SetString(NumberToString(taskIndex + 1), L"state", L"3");
			g_main_cwnd->m_list_info.SetItemText(taskIndex, 6, L"二密错误");
			KillProcess(L"MapleStory.exe");
			ScriptDelay(index, 1000);
			return false;
		}
		dm->MoveToEx(100, 100, 30, 45);
		ScriptDelay(index, 1000);
		if (g_IniFile.GetString(L"Set", L"kou") == L"1") {//登录入口
			ScriptDelay(index, 1000);
			runScript(index, L"loginTag");
			ScriptDelay(index, 1000);

		}
		//输入账号
		if (runScript(index, L"CodeKou1")) {
			ScriptDelay(index, 2000);
			dm->SendString2(g_info[index].hwnd, g_main_cwnd->m_list_info.GetItemText(taskIndex, 1));
			ScriptDelay(index, 1000);
		}
		dm->MoveToEx(100, 100, 30, 45);
		//输入密码
		if (runScript(index, L"PwdKou1")) {
			ScriptDelay(index, 2000);
			dm->SendString2(g_info[index].hwnd, g_main_cwnd->m_list_info.GetItemText(taskIndex, 2));
			ScriptDelay(index, 1000);
		}
		//登录游戏
		ScriptDelay(index, 1000);
		runScript(index, L"login");
		ScriptDelay(index, 3000);
		dm->UseDict(1);

		//strSs.Format(L"火区：%s\n", g_main_cwnd->m_list_info.GetItemText(taskIndex, 4));
		g_main_cwnd->AppendText(strSs);
		if (g_main_cwnd->m_list_info.GetItemText(taskIndex, 4) == L"11" && g_main_cwnd->m_list_info.GetItemText(taskIndex, 11).GetLength()>0) {
			strSs.Format(L"火区账号：%s\n", g_main_cwnd->m_list_info.GetItemText(taskIndex, 11));
			g_main_cwnd->AppendText(strSs);
			dm->FindStrFast(276, 314, 457, 374, g_main_cwnd->m_list_info.GetItemText(taskIndex, 11), L"000000", 1, &x.lVal, &y.lVal);
			strSs.Format(L"火区坐标：%d,%d\n", x.lVal, y.lVal);
			g_main_cwnd->AppendText(strSs);
			if (x.lVal > 0) {

				strSs.Format(L"火区坐标：%d,%d", x.lVal, y.lVal);
				g_main_cwnd->AppendText(strSs);
				dm->MoveTo(x.lVal + RandomNumber(5, 11), y.lVal + RandomNumber(1, 3));
				dm->LeftDoubleClick();
				ScriptDelay(index, 3000);
				dm->MoveToEx(746, 60, 20, 5);
				ScriptDelay(index, 1000);
				dm->LeftClick();
			}
		}
		else if (g_main_cwnd->m_list_info.GetItemText(taskIndex, 4) != L"11" && g_main_cwnd->m_list_info.GetItemText(taskIndex, 11).GetLength() > 0) {
			dm->FindStrFast(276, 314, 457, 374, g_main_cwnd->m_list_info.GetItemText(taskIndex, 11), L"000000", 1, &x.lVal, &y.lVal);
			strSs.Format(L"当前序号:%s,当前账号：%s", g_main_cwnd->m_list_info.GetItemText(taskIndex, 0), g_main_cwnd->m_list_info.GetItemText(taskIndex, 11));
			g_main_cwnd->AppendText(strSs);
			if (x.lVal > 0) {

				strSs.Format(L"账号坐标：%d,%d", x.lVal, y.lVal);
				g_main_cwnd->AppendText(strSs);
				dm->MoveTo(x.lVal + RandomNumber(5, 11), y.lVal + RandomNumber(1, 3));
				dm->LeftDoubleClick();

			}
			ScriptDelay(index, 3000);
			CString sServer;
			sServer.Format(L"loginChoseServer%s.bmp", g_main_cwnd->m_list_info.GetItemText(taskIndex, 4));
			dm->FindPic(655, 0, 771, 539, sServer, L"303030", 0.80, 0, &x.lVal, &y.lVal);
			if (x.lVal > 0) {
				dm->MoveTo(x.lVal + 50, y.lVal + 18);
				ScriptDelay(index, 1000);
				dm->LeftClick();
			}
		}
		else {
			runScript(index, L"checkCode");
			ScriptDelay(index, 3000);
			CString sServer;
			sServer.Format(L"loginChoseServer%s.bmp", g_main_cwnd->m_list_info.GetItemText(taskIndex, 4));
			dm->FindPic(655, 0, 771, 539, sServer, L"303030", 0.80, 0, &x.lVal, &y.lVal);
			if (x.lVal > 0) {
				dm->MoveTo(x.lVal + 50, y.lVal + 18);
				ScriptDelay(index, 1000);
				dm->LeftClick();
			}
		}
		int nCheck = g_main_cwnd->m_trade.GetCheck();
		if (nCheck == 0) {
			if (runScript(index, L"loginServer25")) {
				ScriptDelay(index, 1000);
				dm->KeyPress(13);
			}
		}
		else {
			dm->FindPic(218, 240, 584, 330, L"loginServer9.bmp", L"303030", 0.9, 0, &x.lVal, &y.lVal);
			if (x.lVal > 0) {
				dm->MoveToEx(x.lVal, y.lVal, 10, 5);
				dm->LeftDoubleClick();
			}
		}
		ScriptDelay(index, 1000);

		ScriptDelay(index, 1000);
		
		//g_AccountFile.SetString(, L"state", L"5");
		int a = g_AccountFile.GetInt(NumberToString(taskIndex + 1), L"RoleNum");
		//a = a == 0 ? 1 : a;
		dm->FindPic(1, 0, 210, 52, L"RoleWnd.bmp", L"303030", 0.9, 0, &x.lVal, &y.lVal);
		if (x.lVal > 0) { //选择角色
			CString strPage;
			if (a <8) {// 第一页
				strPage = L"page1.bmp";
			}
			if (a >= 8 && a < 17) {//2
				strPage = L"page2.bmp";
			}
			if (a >= 16 && a < 25) {//3
				strPage = L"page3.bmp";
			}
			if (a >= 24 && a < 33) {//4
				strPage = L"page4.bmp";
			}
			if (a >= 32 && a < 41) {//5
				strPage = L"page5.bmp";
			}
			if (a >= 40 && a < 49) {//6
				strPage = L"page6.bmp";
			}
			if (a >= 48 && a < 57) {//7
				strPage = L"page7.bmp";
			}
			if (a >= 8) {
				if (a % 8 == 0) {
					a = 0;
				}
				else {
					a = a % 8;
				}
			}
			long x1, y1;
			for (size_t k = 0; k < 5; k++)
			{
				dm->FindPic(251, 454, 380, 492, strPage, L"050505", 1, 0, &x.lVal, &y.lVal);
				//如果第一个存在
				if (x.lVal > 0) {
					dm->FindPic(183, 137, 635, 207, L"twoCodeWnd2.bmp", L"050505", 1, 0, &x1, &y1);
					if (x1 > 0)
					{
						break;
					}
					dm->MoveTo(g_Point[a][0], g_Point[a][1]);
					dm->LeftDoubleClick();
					Sleep(RandomNumber(1000, 2000));
					break;
				}
				else {
					dm->MoveToEx(500, 515, 10, 5);
					Sleep(RandomNumber(100, 200));
					dm->LeftClick();
					Sleep(RandomNumber(1000, 2000));
				}
			}


		}
		//二密窗口显示，首次进入
		dm->FindPic(0, 0, 500, 500, L"RoleWnd.bmp", L"303030", 0.9, 0, &x.lVal, &y.lVal);
		if (x.lVal > 0 && !flag) {
			CString str = g_main_cwnd->m_list_info.GetItemText(taskIndex, 3);
			CString code;
			for (int i = 0; i < str.GetLength(); i++)
			{
				//code1 = code1 + code.Mid(i, 1);
				CString strbmp = str.Mid(i, 1) + L".bmp";
				//CString sTwoCode = L"输入二密" + code.Mid(i, 1);
				if (i == str.GetLength() - 1) {
					code += strbmp;
				}
				else {
					code += strbmp + L"|";
				}
			}
			CString strKeyCode = dm->FindPicExS(126, 222, 675, 417, code, L"202020", 0.90, 0);
			CStringArray arr;
			StringSplit(strKeyCode, arr, '|');

			for (size_t i = 0; i < 5; i++)
			{
				if (str.GetLength() == arr.GetCount()) {
					break;
				}
				else {
					dm->MoveTo(RandomNumber(100, 200), RandomNumber(10, 20));
					Sleep(100);
					strKeyCode = dm->FindPicExS(126, 222, 675, 417, code, L"202020", 0.90, 0);
					StringSplit(strKeyCode, arr, '|');
					Sleep(100);
				}
			}

			for (size_t i = 0; i < arr.GetCount(); i++)
			{
				CStringArray arr1;
				StringSplit(arr.GetAt(i), arr1, ',');
				dm->MoveTo(_wtoi(arr1.GetAt(1)) + RandomNumber(5, 10), _wtoi(arr1.GetAt(2)) + RandomNumber(15, 20));
				Sleep(RandomNumber(1300, 1600));
				dm->LeftClick();
				Sleep(RandomNumber(100, 200));
				CString strPwd = dm->FindPicEx(302, 193, 505, 229, L"pwdxing.bmp", L"000000", 1, 0);
				int nCount = strPwd.Replace(L"|", L"|");
				if (strPwd == "") {
					i = -1;
					continue;
				}
				else if (i != nCount) {
					i--;
				}
			}
			for (int i = 0; i < 5; i++)
			{
				dm->FindPic(298, 415, 399, 441, L"enterCode.bmp", L"303030", 0.85, 0, &x.lVal, &y.lVal);
				if (x.lVal > 0) {
					dm->MoveToEx(x.lVal, y.lVal, 10, 5);
					dm->LeftClick();
					dm->delay(1500);
					flag = true;
					break;
				}
			}
		}

		dm->FindPic(281, 213, 524, 350, L"twoCodeError.bmp", L"303030", 0.9, 0, &x.lVal, &y.lVal);
		if (x.lVal > 0) {
			//TODO: 二密错误 处理 
			g_AccountFile.SetString(NumberToString(taskIndex + 1), L"state", L"3");
			g_main_cwnd->m_list_info.SetItemText(taskIndex, 6, L"二密错误");
			KillProcess(L"MapleStory.exe");
			ScriptDelay(index, 1000);
			return false;
		}
		if (flag) {
			dm->delay(1500);
			if (runScript(index, L"taskRun") || runScript(index, L"loginSucess")) {
				return true;
			}
			dm->FindPic(685, 538, 799, 588, L"loginSuccess.bmp|loginSuccess1.bmp", L"303030", 0.9, 0, &x.lVal, &y.lVal);
			if (x.lVal > 0) {
				return true;
			}
			
		}
	}
	return true;
}

//bool CheckRole() {
//	//int a = 22;//取完成次数
//	//
//
//	//dm->FindPic(183, 137, 635, 207, L"twoCodeWnd2.bmp", L"050505", 1, 0, &x, &y);
//	//if (x > 0)
//	//{
//
//	//	CString str = L"qwe123";
//	//	CString code;
//	//	for (int i = 0; i < str.GetLength(); i++)
//	//	{
//
//	//		//code1 = code1 + code.Mid(i, 1);
//	//		CString strbmp = str.Mid(i, 1) + L".bmp";
//	//		//CString sTwoCode = L"输入二密" + code.Mid(i, 1);
//
//	//		if (i == str.GetLength() - 1) {
//	//			code += strbmp;
//	//		}
//	//		else {
//	//			code += strbmp + L"|";
//	//		}
//	//	}
//	//	CString strKeyCode = g_dm->FindPicExS(126, 222, 675, 417, code, L"202020", 0.90, 0);
//	//	CStringArray arr;
//	//	StringSplit(strKeyCode, arr, '|');
//
//	//	for (size_t i = 0; i < arr.GetCount(); i++)
//	//	{
//	//		CStringArray arr1;
//	//		StringSplit(arr.GetAt(i), arr1, ',');
//	//		g_dm->MoveTo(_wtoi(arr1.GetAt(1)) + RandomNumber(5, 10), _wtoi(arr1.GetAt(2)) + RandomNumber(15, 20));
//	//		Sleep(RandomNumber(1000, 1600));
//	//		g_dm->LeftClick();
//	//		Sleep(RandomNumber(100, 200));
//	//	}
//
//	//}
//}

bool StartLoginGame(long index, int taskIndex, bool flagLogin) {
	VARIANT x, y;
	bool flag = false;
	dmsoft *dm = g_info[index].dm;
	dm->MoveWindow(g_info[index].hwnd, 0, 0);
	dm->UseDict(1);
	while (g_flag)
	{
		CString strSs;
		strSs.Format(L"开始登录", g_main_cwnd->m_list_info.GetItemText(taskIndex, 4));
		g_main_cwnd->AppendText(strSs);
		
		//账号
		dm->FindPic(288, 220, 510, 301, L"onLineCode.bmp", L"202020", 0.8, 0, &x.lVal, &y.lVal);
		if (x.lVal > 0) {
			g_AccountFile.SetString(NumberToString(taskIndex + 1), L"state", L"5");
			g_main_cwnd->m_list_info.SetItemText(taskIndex, 6, L"账号在线");
			KillProcess(L"MapleStory.exe");
			ScriptDelay(index, 1000);
			return false;
		}
		if (runScript(index,L"codeError") || runScript(index,L"codeError1")) {
			g_AccountFile.SetString(NumberToString(taskIndex + 1), L"state", L"2");
			g_main_cwnd->m_list_info.SetItemText(taskIndex, 6, L"账号错误");
			KillProcess(L"MapleStory.exe");
			ScriptDelay(index, 1000);
			return false;
		}
		if (runScript(index,L"twoPwdError")) {
			g_AccountFile.SetString(NumberToString(taskIndex + 1), L"state", L"3");
			g_main_cwnd->m_list_info.SetItemText(taskIndex, 6, L"二密错误");
			KillProcess(L"MapleStory.exe");
			ScriptDelay(index, 1000);
			return false;	
		}
		dm->MoveToEx(100, 100, 30, 45);
		ScriptDelay(index, 1000);
		if (g_IniFile.GetString(L"Set", L"kou") == L"1") {//登录入口
			ScriptDelay(index, 1000);
			runScript(index, L"loginTag");
			ScriptDelay(index, 1000);

		}
		//输入账号
		if (runScript(index, L"CodeKou1")) {
			ScriptDelay(index, 2000);
			dm->SendString2(g_info[index].hwnd, g_main_cwnd->m_list_info.GetItemText(taskIndex, 1));
			ScriptDelay(index, 1000);
		}
		dm->MoveToEx(100, 100, 30, 45);
		//输入密码
		if (runScript(index, L"PwdKou1")) {
			ScriptDelay(index, 2000);
			dm->SendString2(g_info[index].hwnd, g_main_cwnd->m_list_info.GetItemText(taskIndex, 2));
			ScriptDelay(index, 1000);
		}
		//登录游戏
		ScriptDelay(index, 1000);
		runScript(index, L"login");
		ScriptDelay(index, 3000);
		dm->UseDict(1);
		
		//strSs.Format(L"火区：%s\n", g_main_cwnd->m_list_info.GetItemText(taskIndex, 4));
		g_main_cwnd->AppendText(strSs);
		if (g_main_cwnd->m_list_info.GetItemText(taskIndex, 4) == L"11" && g_main_cwnd->m_list_info.GetItemText(taskIndex, 11).GetLength()>0) {
			strSs.Format(L"火区账号：%s\n" ,g_main_cwnd->m_list_info.GetItemText(taskIndex, 11));
			g_main_cwnd->AppendText(strSs);
			dm->FindStrFast(276, 314, 457, 374, g_main_cwnd->m_list_info.GetItemText(taskIndex, 11), L"000000",1, &x.lVal, &y.lVal);
			strSs.Format(L"火区坐标：%d,%d\n" , x.lVal, y.lVal);
			g_main_cwnd->AppendText(strSs);
			if (x.lVal > 0) {
				
				strSs.Format(L"火区坐标：%d,%d" ,x.lVal, y.lVal);
				g_main_cwnd->AppendText(strSs);
				dm->MoveTo(x.lVal + RandomNumber(5, 11), y.lVal + RandomNumber(1, 3));
				dm->LeftDoubleClick();
				ScriptDelay(index, 3000);
				dm->MoveToEx(746, 60, 20, 5);
				ScriptDelay(index, 1000);
				dm->LeftClick();
			}
		}
		else if (g_main_cwnd->m_list_info.GetItemText(taskIndex, 4) != L"11" && g_main_cwnd->m_list_info.GetItemText(taskIndex, 11).GetLength() > 0) {
			dm->FindStrFast(276, 314, 457, 374, g_main_cwnd->m_list_info.GetItemText(taskIndex, 11), L"000000", 1, &x.lVal, &y.lVal);
			strSs.Format(L"当前序号:%s,当前账号：%s", g_main_cwnd->m_list_info.GetItemText(taskIndex, 0),g_main_cwnd->m_list_info.GetItemText(taskIndex, 11));
			g_main_cwnd->AppendText(strSs);
			if (x.lVal > 0) {

				strSs.Format(L"账号坐标：%d,%d", x.lVal, y.lVal);
				g_main_cwnd->AppendText(strSs);
				dm->MoveTo(x.lVal + RandomNumber(5, 11), y.lVal + RandomNumber(1, 3));
				dm->LeftDoubleClick();
				
				
			}
			ScriptDelay(index, 3000);
			CString sServer;
			sServer.Format(L"loginChoseServer%s.bmp", g_main_cwnd->m_list_info.GetItemText(taskIndex, 4));
			dm->FindPic(655, 0, 771, 539, sServer, L"303030", 0.80, 0, &x.lVal, &y.lVal);
			if (x.lVal > 0) {
				dm->MoveTo(x.lVal + 50, y.lVal + 18);
				ScriptDelay(index, 1000);
				dm->LeftClick();
			}
		}
		else {
			runScript(index, L"checkCode");
			ScriptDelay(index, 3000);
			CString sServer;
			sServer.Format(L"loginChoseServer%s.bmp", g_main_cwnd->m_list_info.GetItemText(taskIndex, 4));
			dm->FindPic(655, 0, 771, 539, sServer, L"303030", 0.80, 0, &x.lVal, &y.lVal);
			if (x.lVal > 0) {
				dm->MoveTo(x.lVal + 50, y.lVal + 18);
				ScriptDelay(index,1000);
				dm->LeftClick();
			}
		}
		int nCheck= g_main_cwnd->m_trade.GetCheck();
		if (nCheck == 0) {
			if (runScript(index, L"loginServer25")) {
				ScriptDelay(index, 1000);
				dm->KeyPress(13);
			}
		}
		else {
			dm->FindPic(218, 240, 584, 330, L"loginServer9.bmp", L"303030", 0.9, 0, &x.lVal, &y.lVal);
			if (x.lVal > 0) {
				dm->MoveToEx(x.lVal, y.lVal, 10, 5);
				dm->LeftDoubleClick();
			}
		}
		ScriptDelay(index, 1000);

		ScriptDelay(index, 1000);

		int a = 0;
		//a = a == 0 ? 1 : a;
		dm->FindPic(1, 0, 210, 52, L"RoleWnd.bmp", L"303030", 0.9, 0, &x.lVal, &y.lVal);
		if (x.lVal > 0) { //选择角色
			CString strPage;
			if (a <8) {// 第一页
				strPage = L"page1.bmp";
			}
			if (a >= 8 && a < 17) {//2
				strPage = L"page2.bmp";
			}
			if (a >= 16 && a < 25) {//3
				strPage = L"page3.bmp";
			}
			if (a >= 24 && a < 33) {//4
				strPage = L"page4.bmp";
			}
			if (a >= 32 && a < 41) {//5
				strPage = L"page5.bmp";
			}
			if (a >= 40 && a < 49) {//6
				strPage = L"page6.bmp";
			}
			if (a >= 48 && a < 57) {//7
				strPage = L"page7.bmp";
			}
			if (a >= 8) {
				if (a % 8 == 0) {
					a = 0;
				}
				else {
					a = a % 8;
				}
			}
			long x1, y1;
			for (size_t k = 0; k < 8; k++)
			{
				dm->FindPic(251, 454, 380, 492, strPage, L"050505", 1, 0, &x.lVal, &y.lVal);
				//如果第一个存在
				if (x.lVal > 0) {
					dm->FindPic(183, 137, 635, 207, L"twoCodeWnd2.bmp", L"050505", 1, 0, &x1, &y1);
					if (x1 > 0)
					{
						break;
					}
					dm->MoveTo(g_Point[a][0], g_Point[a][1]);
					dm->LeftDoubleClick();
					Sleep(RandomNumber(1000, 2000));
					break;
				}
				else {
					dm->MoveToEx(500, 515, 10, 5);
					Sleep(RandomNumber(200, 300));
					dm->LeftClick();
					Sleep(RandomNumber(1500, 2000));
				}
			}


		}
		//二密窗口显示，首次进入
		dm->FindPic(0, 0, 500, 500, L"RoleWnd.bmp", L"303030", 0.9, 0, &x.lVal, &y.lVal);
		if (x.lVal > 0 && !flag) {
			CString str = g_main_cwnd->m_list_info.GetItemText(taskIndex, 3);
			CString code;
			for (int i = 0; i < str.GetLength(); i++)
			{
				//code1 = code1 + code.Mid(i, 1);
				CString strbmp = str.Mid(i, 1) + L".bmp";
				//CString sTwoCode = L"输入二密" + code.Mid(i, 1);
				if (i == str.GetLength() - 1) {
					code += strbmp;
				}
				else {
					code += strbmp + L"|";
				}
			}
			CString strKeyCode = dm->FindPicExS(126, 222, 675, 417, code, L"202020", 0.90, 0);
			CStringArray arr;
			StringSplit(strKeyCode, arr, '|');

			for (size_t i = 0; i < 5; i++)
			{
				if (str.GetLength() == arr.GetCount()) {
					break;
				}
				else {
					dm->MoveTo(RandomNumber(100, 200), RandomNumber(10, 20));
					Sleep(100);
					strKeyCode = dm->FindPicExS(126, 222, 675, 417, code, L"202020", 0.90, 0);
					StringSplit(strKeyCode, arr, '|');
					Sleep(100);
				}
			}

			for (size_t i = 0; i < arr.GetCount(); i++)
			{
				CStringArray arr1;
				StringSplit(arr.GetAt(i), arr1, ',');
				dm->MoveTo(_wtoi(arr1.GetAt(1)) + RandomNumber(5, 10), _wtoi(arr1.GetAt(2)) + RandomNumber(15, 20));
				Sleep(RandomNumber(1000, 1600));
				dm->LeftClick();
				Sleep(RandomNumber(100, 200));
				CString strPwd = dm->FindPicEx(302, 193, 505, 229, L"pwdxing.bmp", L"000000", 1, 0);
				int nCount = strPwd.Replace(L"|", L"|");
				if (strPwd == "") {
					i = -1;
					continue;
				}
				else if (i != nCount) {
					i--;
				}
			}
			for (int i = 0; i < 5; i++)
			{
				dm->FindPic(298, 415, 399, 441, L"enterCode.bmp", L"303030", 0.85, 0, &x.lVal, &y.lVal);
				if (x.lVal > 0) {
					dm->MoveToEx(x.lVal, y.lVal, 10, 5);
					dm->LeftClick();
					dm->delay(1500);
					flag = true;
					break;
				}
			}
		}


		//if (runScript(index, L"twoCodeWnd")) {
		//	ScriptDelay(index, 1000);
		//	//dm->KeyPress(13);
		//}

		//if (runScript(index,L"twoCodeKey") > 0 && !flag) {
		//	CString code = g_main_cwnd->m_list_info.GetItemText(taskIndex, 3);
		//	CString code1;
		//	ScriptDelay(index, 1500);
		//	for (size_t i = 0; i < 2; i++)
		//	{
		//		ScriptDelay(index, 2500);
		//		dm->MoveToEx(RandomNumber(200, 300), 100, 30, 45);
		//		ScriptDelay(index,2500);
		//	}
		//	for (int i = 0; i < code.GetLength(); i++)
		//	{
		//		
		//		ScriptDelay(index,1500);
		//		code1 = code1 + code.Mid(i, 1);
		//		CString strbmp = code.Mid(i, 1) + L".bmp";
		//		CString sTwoCode = L"输入二密" + code.Mid(i, 1);
		//		
		//		dm->FindPic(126, 222, 675, 417, strbmp, L"202020", 0.90, 0, &x.lVal, &y.lVal);
		//		long curX, curY;
		//		if (x.lVal > 0) {
		//			x.lVal = x.lVal + RandomNumber(5, 5)+10;
		//			y.lVal = y.lVal + RandomNumber(5, 5) + 5;
		//			dm->MoveTo(x.lVal, y.lVal);
		//			ScriptDelay(index, 500);
		//			
		//			for (size_t i = 0; i < 5; i++)
		//			{
		//				dm->GetCursorPos(&curX, &curY);
		//				ScriptDelay(index, 100);
		//				if (curX!= x.lVal) {
		//					ScriptDelay(index, 1500);
		//					dm->MoveTo(x.lVal, y.lVal);
		//				}
		//			}
		//			
		//			dm->LeftClick();
		//			ScriptDelay(index, 1000);
		//		}
		//		dm->MoveToEx(RandomNumber(200, 300), 100, 30, 45);
		//	}
		//	for (int i = 0; i < 5; i++)
		//	{
		//		dm->FindPic(298, 415, 399, 441, L"enterCode.bmp", L"303030", 0.85, 0, &x.lVal, &y.lVal);
		//		if (x.lVal > 0) {
		//			dm->MoveToEx(x.lVal, y.lVal, 10, 5);
		//			dm->LeftClick();
		//			dm->delay(1500);
		//			flag = true;
		//			break;
		//		}
		//	}
		//}



		dm->FindPic(281, 213, 524, 350, L"twoCodeError.bmp", L"303030", 0.9, 0, &x.lVal, &y.lVal);
		if (x.lVal > 0) {
			//TODO: 二密错误 处理 
			g_AccountFile.SetString(NumberToString(taskIndex + 1), L"state", L"3");
			g_main_cwnd->m_list_info.SetItemText(taskIndex, 6, L"二密错误");
			KillProcess(L"MapleStory.exe");
			ScriptDelay(index, 1000);
			return false;
		}
		if (flag) {
			dm->delay(1500);
			if (runScript(index,L"taskRun") || runScript(index,L"loginSucess")) {
				return true;
			}
			dm->FindPic(685, 538, 799, 588, L"loginSuccess.bmp|loginSuccess1.bmp", L"303030", 0.9, 0, &x.lVal, &y.lVal);
			{
				if (x.lVal > 0) {
					return true;
				}
			}
		}
	}
}

bool StartTaskZhaKun(long index, int taskIndex) {
	long x, y, x1, y1;
	int j=0, k=0,c=0;
	dmsoft *dm = g_info[index].dm;
	int nTime = 0;
	dm->SetWindowState(g_info[index].hwnd, 12);
	CString jinbi;
	//查找是否为法师
	//if (runScript(index, L"isRole")) {
	//	g_info[index].key = 17;
	//}
	//else {
	//	g_info[index].key = 18;
	//}
	dm->UseDict(0);
	bool isZHeng = false;
	while (g_flag)
	{
		nTime = GetTickCount();
		CloseWnd(index);
		choseMap(index,taskIndex);
		dm->FindPic(0, 0, 310, 88, L"mapsiwu.bmp", L"050505", 1, 0, &x, &y);
		if (x > 0) {

			Sleep(2000);
			if (g_nState == 0) {
				dm->MoveTo(x + RandomNumber(100, 200), y + 200);
				g_nState = 1;
				Sleep(RandomNumber(100, 200));
				dm->KeyPress(49);
				//Sleep(RandomNumber(100, 200));
				Sleep(RandomNumber(4000, 5500));
			}
		}
		if (g_nState == 1) {//首次进入地图移动
			dm->KeyDown(39);
			//Sleep(2500,3000);
			Sleep(RandomNumber(3000, 3200));
			dm->KeyUp(39);
			g_nState = 2;
		}
		if (g_nState == 2) {
			//查找npcA
			dm->FindPic(0, 551, 1017, 673, L"npcA.bmp", L"050505", 1, 0, &x, &y);
			if (x > 0) {
				c = 0;
				dm->KeyDown(37);
				//Sleep(2500,3000);
				Sleep(RandomNumber(1500, 1600));
				dm->KeyUp(37);
				g_nState = 3;
				isZHeng = false;
				j = 0;
			}
			++c;
			if (c > 100) {
				g_nState = 1;
				c = 0;
			}
		}
		if (g_nState == 3) {
			//打开背包
			int nRet = dm->FindPic(0, 0, 1017, 673, L"bagWnd.bmp|bagWnd1.bmp", L"000000", 1, 0, &x1, &y1);
			if (x1 > 0) {

				//装备栏是否选中 选中点整理
				//物品栏是否选中 选中点整理
				//装饰兰是否选中 选中整理

				//选中武器栏 点击整理
				//选中物品栏 点击整理
				//选中装饰兰 点击整理
				if (!isZHeng) {
					CString str;
					str.Format(L"进入整理1");
					g_main_cwnd->AppendText(str);
					Sleep(RandomNumber(1000, 2000));
					isZHeng = ZhengLi(index, taskIndex);
					Sleep(RandomNumber(1000, 2000));
				}

				//dm->FindPic(0, 0, 1017, 673, L"kuoda.bmp", L"050505", 0.9, 0, &x, &y);
				//if (x > 0) {
				//	Sleep(1000);
				//	dm->MoveTo(x + 10, y + 10);
				//	dm->LeftClick();
				//	Sleep(1000);
				//}
				dm->FindPic(0, 0, 1017, 773, L"suoxiao.bmp|zhengli1.bmp", L"101010", 0.9, 0, &x, &y);
				if (x > 0) {
					g_main_cwnd->AppendText(L"开始丢球");
					CString strNum;
					dm->MoveToEx(x1 - 219, y1 + 25, 5, 3);
					dm->LeftClick();
					Sleep(RandomNumber(180, 220));
					dm->MoveTo(x1 - 219, y1 - RandomNumber(30, 50));
					Sleep(1000);
					dm->FindPic(0, 0, 1017, 673, L"qiu.bmp", L"050505", 0.9, 0, &x, &y);
					if (x > 0) {
						g_main_cwnd->AppendText(L"丢球成功");
						dm->MoveToEx(x + 10, y + 10, 10, 10);
						dm->LeftClick();
						Sleep(RandomNumber(800, 1000));
						dm->MoveTo(RandomNumber(500, 600), RandomNumber(350, 450));
						Sleep(RandomNumber(800, 1000));
						dm->LeftClick();
						Sleep(RandomNumber(1000, 1500));
						for (size_t i = 0; i < 10; i++)
						{
							int nColNum = dm->GetColorNum(200, 569, 814, 670, L"e0cfaa-050505", 0.95);
							if (nColNum>800) {
								strNum.Format(L"颜色数量:%d", nColNum);
								g_main_cwnd->AppendText(strNum);
								dm->KeyPress(73);
								Sleep(200);
								g_nState = 4;
								break;
							}
							Sleep(100);
						}
					}
				}
			}
			else {
				dm->KeyPress(73);
				Sleep(1500);
			}
			for (size_t i = 0; i < 5; i++)
			{
				Sleep(500);
				int nColNum = dm->GetColorNum(200, 569, 814, 670, L"e0cfaa-050505", 0.95);
				if (nColNum>800) {
					dm->KeyPress(73);
					Sleep(1500);
					g_nState = 4;
					break;
				}
			}

		}
		if (g_nState == 4) {
			dm->FindPic(0, 0, 1017, 673, L"wu1.bmp|wu2.bmp|wu3.bmp|wu4.bmp|wuqiu.bmp|wuqiu1.bmp", L"050505", 1, 0, &x, &y);
			if (x > 0) {
				j = 0;
				g_nState = 5;
			}
			//dm->FindPic(0, 0, 1017, 673, L"qiu.bmp", L"050505", 1, 0, &x, &y);
			//if (x > 0) {
			//	k++;
			//	Sleep(500);
			//}

			//if (k > 10) {
			//	dm->KeyPress(90);
			//	dm->KeyDown(37);

			//	Sleep(RandomNumber(5000, 5500));
			//	dm->KeyUp(37);

			//	Sleep(1000);
			//	dm->KeyDown(39);

			//	Sleep(RandomNumber(1500, 2000));
			//	dm->KeyUp(39);
			//	g_nState = 1;
			//}
			g_main_cwnd->AppendText(L"开始攻击");
			for (size_t i = 0; i < RandomNumber(15, 20); i++)
			{
				//CString strNum;
				//strNum.Format(L"颜色数量:%d", dm->GetColorNum(288, 569, 814, 670, L"e0cfaa-050505", 0.95));
				//g_main_cwnd->AppendText(strNum);
				dm->KeyDown(16);
				Sleep(RandomNumber(80, 120));
				dm->KeyUp(16);
				g_main_cwnd->AppendText(L"攻击中");
			}
			g_main_cwnd->AppendText(L"继续攻击");
			dm->FindPic(0, 0, 510, 400, L"mapS2.bmp", L"050505", 1, 0, &x, &y);
			if (x > 0) {
				g_nState = 6;
			}
		}
		if (g_nState == 5) {
			for (size_t ii = 0; ii < 10; ii++)
			{
				dm->FindPic(0, 0, 1017, 673, L"wu1.bmp|wu2.bmp|wu3.bmp|wu4.bmp|wuqiu.bmp|wuqiu1.bmp", L"101010", 0.9, 0, &x, &y);
				if (x > 0) {
					break;
				}
				Sleep(50);
			}
			if (x > 0) {
				dm->KeyDown(37);
				Sleep(RandomNumber(100, 200));

				for (size_t i = 0; i < RandomNumber(45, 50); i++)
				{
					dm->KeyDown(90);
					Sleep(RandomNumber(80, 120));
					dm->KeyUp(90);
				}
				dm->KeyUp(37);
				dm->KeyUp(90);
				Sleep(RandomNumber(400, 600));

				dm->KeyDown(39);
				Sleep(RandomNumber(100, 200));
				for (size_t i = 0; i < RandomNumber(50, 55); i++)
				{
					dm->KeyDown(90);
					Sleep(RandomNumber(80, 120));
					dm->KeyUp(90);
				}
				Sleep(RandomNumber(1300, 1500));
				dm->KeyUp(39);
				dm->KeyUp(90);
			}
			if (x == -1) {
				j++;
				
			}
			if (j > 2) {
				g_nState = 6;
			}
			Sleep(1000);
		}
		if (g_nState == 6) {
			dm->FindPic(0, 0, 1017, 673, L"wu1.bmp|wu2.bmp|wu3.bmp|wu4.bmp|wuqiu.bmp|wuqiu1.bmp", L"050505", 0.9, 0, &x, &y);
			if (x > 0) {
				g_nState = 5;
			}
			dm->FindPic(0, 0, 510, 400, L"mapS2.bmp", L"050505", 1, 0, &x, &y);
			if (x > 0) {
				dm->FindPic(0, 0, 1017, 673, L"bagWnd.bmp|bagWnd1.bmp", L"000000", 1, 0, &x1, &y1);
				if (x1 > 0){
					dm->KeyPress(73);
				}
				dm->KeyDown(37);
				Sleep(100);
				for (size_t i = 0; i < 20; i++)
				{
					dm->KeyPress(38);
					Sleep(RandomNumber(80, 120));
				}
				Sleep(RandomNumber(2000, 2500));
				dm->FindPic(0, 0, 510, 400, L"mapS2.bmp", L"050505", 1, 0, &x, &y);
				if (x > 0) {
					dm->KeyUp(37);
					dm->KeyUp(38);
					Sleep(400);
					dm->KeyDown(39);
					for (size_t i = 0; i < 20; i++)
					{
						dm->KeyPress(38);
						Sleep(RandomNumber(80, 120));
					}
					Sleep(RandomNumber(1000, 1500));

				}
				dm->KeyUp(39);
				dm->KeyUp(38);
			}
			else {

				bool bflag = true;
				if (!bflag) {//金币未达到300万货没有卡片
					//是否超过3天，超过3天执行清理装备

				}
				else {

					dm->FindPic(0, 0, 310, 88, L"mapsiwu.bmp", L"050505", 1, 0, &x, &y);
					if (x > 0) {
						Sleep(500);
						dm->KeyPress(32);
						Sleep(500);
					}
					dm->FindPic(0, 0, 1017, 673, L"exitOk.bmp", L"050505", 1, 0, &x, &y);
					if (x > 0) {
						dm->MoveToEx(x, y, 5, 5);
						dm->LeftClick();
						Sleep(RandomNumber(200, 300));
						dm->MoveTo(x - RandomNumber(100, 200), y - RandomNumber(100, 200));
					}
					dm->FindPic(0, 0, 1017, 673, L"exitOk1.bmp", L"050505", 1, 0, &x, &y);
					if (x > 0) {
						dm->MoveToEx(x - 50, y, 5, 5);
						dm->LeftClick();
						Sleep(RandomNumber(200, 300));
						dm->MoveTo(x - RandomNumber(100, 200), y - RandomNumber(100, 200));
					}
				}
			}
		}
		if (g_nState == 7) {

			if (g_AccountFile.GetInt(NumberToString(taskIndex + 1), L"RoleNum") == 0) {//第一个角色关闭组队
				/*for (size_t i = 0; i < 5; i++)
				{
					Sleep(150);
					dm->FindPic(697, 517, 1024, 609, L"teamXue.bmp", L"050505", 1, 0, &x, &y);
					if (x > 0) {
						dm->FindPic(37, 167, 1005, 424, L"teamList.bmp", L"101010", 1, 0, &x, &y);
						if (x > 0) {
							dm->FindPic(0, 167, 1005, 824, L"exitTeam.bmp", L"101010", 1, 0, &x, &y);
							if (x > 0) {
								dm->MoveToEx(x, y, 10, 10);
								dm->LeftClick();
								Sleep(RandomNumber(100, 150));
								dm->MoveToEx(x + 100, y + 100, 100, 100);
							}
						}
						else {
							dm->KeyPress(80);
							Sleep(RandomNumber(1000, 1500));
						}
					}
					else {
						dm->FindPic(37, 167, 1005, 424, L"teamList.bmp", L"101010", 1, 0, &x, &y);
						if (x > 0) {
							dm->KeyPress(80);
							Sleep(RandomNumber(1000, 1500));
						}
					}
				}*/

			}

			dm->FindPic(37, 167, 1005, 424, L"teamList.bmp", L"101010", 1, 0, &x, &y);
			if (x > 0) {
				dm->KeyPress(80);
				Sleep(RandomNumber(1000, 1500));
			}

			dm->FindPic(263, 320, 397, 481, L"exit.bmp", L"050505", 1, 0, &x, &y);
			if (x > 0) {
				Sleep(200);
				dm->KeyPress(27);
				Sleep(RandomNumber(200, 300));
			}
			ClearEquip(index);

		}
		if (g_nState == 8) {
			
			for (size_t i = 0; i < 5; i++)
			{
				dm->FindPic(800, 0, 1024, 50, L"red.bmp", L"101010", 0.9, 0, &x, &y);
				if (x > 0) {
					int nRoleNum = g_AccountFile.GetInt(NumberToString(taskIndex + 1), L"RoleNum");
					++nRoleNum;
					//g_main_cwnd->m_list_info.SetItemText(taskIndex, 6, L"完成");
					//g_AccountFile.SetString(NumberToString(taskIndex + 1), L"state", L"1");
					g_AccountFile.SetInt(NumberToString(taskIndex + 1), L"RoleNum", nRoleNum);
					g_main_cwnd->m_list_info.SetItemText(taskIndex, 7, NumberToString(nRoleNum));
					g_nState = 9;
					break;
				}
			}
			if (x > 0) {//红电脑跳出当前循环
				continue;
			}
			dm->FindPic(0, 0, 500, 300, L"mapJy.bmp", L"101010", 1, 0, &x, &y);
			if (x > 0) {
				g_nState = 7;
			}
			dm->FindPic(0, 0, 510, 400, L"mapB.bmp", L"050505", 1, 0, &x, &y);
			if (x > 0) {//到达交易地图
				Trade(index,taskIndex);
			}
			else {
				Sleep(RandomNumber(80, 120));
				dm->FindPic(119, 52, 732, 294, L"bTag.bmp", L"202020", 0.90, 0, &x, &y);
				if (x == -1)
				{
					dm->KeyPress(66);
				}
				else {
					dm->MoveTo(x + 20, y + 3);
					dm->LeftClick();
					Sleep(RandomNumber(80, 120));
				}
			}
		}
		if (g_nState == 9) {
			 
			g_main_cwnd->AppendText(L"当前状态:" + NumberToString(g_nState));
			//当前进行的角色+1 如果等于进行的总数则切换账号
			int nRoleNum = g_AccountFile.GetInt(NumberToString(taskIndex + 1), L"RoleNum");
			int nZhaNum = g_AccountFile.GetInt(NumberToString(taskIndex + 1), L"ZhaNum");
			if (nRoleNum >= nZhaNum) {//切换账号
				/*g_bSwicth=true;
				g_main_cwnd->m_list_info.SetItemText(taskIndex, 6, L"完成");
				g_AccountFile.SetString(NumberToString(taskIndex + 1), L"state", L"1");*/

				g_main_cwnd->m_list_info.SetItemText(taskIndex, 6, L"完成");//当前账号置完成
				taskIndex = taskIndex + 1;
				g_AccountFile.SetString(NumberToString(taskIndex), L"state", L"1");

				int nLineCode = g_IniFile.GetInt(L"Set", L"CodeLine");//当前配置线路
				int nLineCode1 = _wtoi(g_main_cwnd->m_list_info.GetItemText(taskIndex, 12));
				if (nLineCode == nLineCode1) {
					//切换角色
					SwicthRole(index, taskIndex,true,true);//切换下一账号
				}
				else {
					g_nState = 0;
					return true;
				}
			}
			else {
				SwicthRole(index, taskIndex, true,false);//切换下一角色
				g_nState = 0;
				g_main_cwnd->AppendText(L"当前状态:" + NumberToString(g_nState));
			}
		}
		if (g_nState == 10) {
			Sleep(5000);
			g_nState = 9;
		}

		CTime  tm = CTime::GetCurrentTime();
		CString str = tm.Format("%H:%M:%S");
		g_main_cwnd->AppendText(L"当前时间:"+str + L"当前状态:" + NumberToString(g_nState));

		dm->FindPic(0, 0, 1024, 700, L"jyWndNo.bmp|jyWndNo1.bmp", L"101010", 1, 0, &x, &y);
		if (x > 0) {
			dm->MoveTo(x + 10 + RandomNumber(1, 33), y + RandomNumber(30, 33));
			dm->LeftClick();
			Sleep(RandomNumber(100, 200));
		}
	}
	g_main_cwnd->AppendText(L"当前任务结束"+NumberToString(taskIndex));
	return true;

}

bool StartTask(long index,int taskIndex) {
	dmsoft *dm = g_info[index].dm;
	bool bRoleState = true;
	long x=0, y=0,j=0,k=0,l=0,intX=0,intY=0;
	bool bCheckArms = true;
	bool findNpc = true;
	bool findpic = false;
	dm->SetWindowState(g_info[index].hwnd, 12);
	CString jinbi;
	//查找是否为法师
	if (runScript(index, L"isRole")) {
		g_info[index].key = 17;
	}
	else {
		g_info[index].key = 18;
	}
	dm->UseDict(0);
	while (g_flag)
	{
		dm->MoveToEx(1000, RandomNumber(200, 300), 30, 45);
		CString taskStr = L"loginOkWnd|closeWnd|closeWnd1|closeWnd4";
		runScriptList(index,taskStr);
		dm->FindPic(539, 372, 671, 468, L"loginOkWnd.bmp", L"101010", 0.9, 0, &x, &y);
		if (x > 0) {
			dm->MoveTo(x+10, y+3);
			Sleep(1000);
			dm->LeftClick();
			Sleep(1000);
		}

		dm->FindPic(500, 417, 1024, 709, L"teamXue.bmp", L"050505", 1, 0, &x, &y);
		if (x > 0) {
			for (size_t i = 0; i < 6; i++)
			{
				dm->FindPic(37, 167, 1005, 424, L"teamList.bmp", L"101010", 1, 0, &x, &y);
				if (x > 0) {
					dm->FindPic(0, 167, 1005, 824, L"exitTeam.bmp", L"101010", 1, 0, &x, &y);
					if (x > 0) {
						dm->MoveToEx(x, y, 10, 10);
						dm->LeftClick();
						Sleep(RandomNumber(100, 150));
						dm->MoveToEx(x + 100, y + 100, 100, 100);
					}
				}
				else {
					dm->KeyPress(80);
					Sleep(RandomNumber(1000, 1500));
				}
				Sleep(100);
			}
		}

		//检查角色
		if (g_AccountFile.GetInt(NumberToString(taskIndex + 1), L"state") == 6 || g_main_cwnd->m_trade.GetCheck()==1) {//状态等于boss已完成或选中交易
			//如果不是火区则查是否黄电脑
			if (g_main_cwnd->m_list_info.GetItemText(taskIndex, 4) != L"11") {
				//如果有子账号 //查看是否红电脑。
				CString taskStr = L"loginOkWnd|closeWnd|closeWnd1|closeWnd4";
				runScriptList(index, taskStr);

				if (g_main_cwnd->m_trade.GetCheck() == 0) {
					//Sleep(1000);
					//moveKey(index, 27, 200);
					//Sleep(1000);
					g_main_cwnd->m_list_info.SetItemText(taskIndex, 6, L"完成");
					g_AccountFile.SetString(NumberToString(taskIndex + 1), L"state", L"1");

					Sleep(2000);
					//取配置线路和列表线路比较如何不等则换线
					int nLineCode = g_IniFile.GetInt(L"Set", L"CodeLine");//当前配置线路
					int nLineCode1 = _wtoi(g_main_cwnd->m_list_info.GetItemText(taskIndex + 1, 12));
					if (nLineCode == nLineCode1) {
						DoWork(index, taskIndex + 1, true);
					}

					g_flag = false;
					return true;
				}
				if (g_main_cwnd->m_list_info.GetItemText(taskIndex, 11).GetLength() > 0) {
					//有子账号查是否红电脑854,-1,1025,46
					dm->FindPic(800, 0, 1024, 50, L"red.bmp", L"101010", 0.9, 0, &x, &y);
					if (x > 0) {//找到红电脑 
						Sleep(1000);
						moveKey(index, 27, 200);
						Sleep(1000);
						g_main_cwnd->m_list_info.SetItemText(taskIndex, 6, L"完成");
						g_AccountFile.SetString(NumberToString(taskIndex + 1), L"state", L"1");
						
						Sleep(2000);
						//取配置线路和列表线路比较如何不等则换线
						int nLineCode = g_IniFile.GetInt(L"Set", L"CodeLine");//当前配置线路
						int nLineCode1 = _wtoi(g_main_cwnd->m_list_info.GetItemText(taskIndex + 1, 12));
						if (nLineCode == nLineCode1) {
							DoWork(index, taskIndex + 1, true);
						}

						g_flag = false;
						return true;
					}
				}
				else {
					dm->FindPic(189, 132, 889, 479, L"yellwo.bmp", L"101010", 0.9, 0, &x, &y);
					if (x > 0) {
						moveKey(index, 27, 200);
					}
					if (!findpic) {
						for (size_t i = 0; i < 5; i++)
						{
							CString taskStr = L"loginOkWnd|closeWnd|closeWnd1|closeWnd4";
							runScriptList(index, taskStr);
							dm->FindColor(770, 730, 774, 737, L"23aae2", 0.98, 0, &x, &y);
							if (x > 0) {
								dm->MoveTo(x, y);
								Sleep(1000);
								dm->LeftClick();
								Sleep(1000);
								dm->MoveTo(x, y - 98);
								Sleep(1000);
								dm->LeftClick();
								Sleep(1000);
								for (size_t j = 0; j < 5; j++)
								{
									CString taskStr = L"loginOkWnd|closeWnd|closeWnd1|closeWnd4";
									runScriptList(index, taskStr);

									dm->FindPic(189, 132, 889, 479, L"yellwo.bmp", L"101010", 0.9, 0, &x, &y);
									if (x > 0) {
										long x1;
										dm->FindPic(189, 132, 889, 479, L"yellwobi.bmp", L"101010", 0.9, 0, &x1, &y);
										if (x1 > 0) {
											g_main_cwnd->m_list_info.SetItemText(taskIndex, 10, L"50%");
										}
										findpic = true;
										i = 5;
										moveKey(index, 27, 200);
										break;
									}
									Sleep(1000);
								}
								//if (x == -1) {
								//	Sleep(1000);
								//	moveKey(index, 27, 200);
								//	Sleep(1000);
								//	g_main_cwnd->m_list_info.SetItemText(taskIndex, 6, L"完成");
								//	g_AccountFile.SetString(NumberToString(taskIndex + 1), L"state", L"1");
								//	findpic = true;
								//	i = 5;
								//	Sleep(2000);
								//	//取配置线路和列表线路比较如何不等则换线
								//	int nLineCode = g_IniFile.GetInt(L"Set", L"CodeLine");//当前配置线路
								//	int nLineCode1 = _wtoi(g_main_cwnd->m_list_info.GetItemText(taskIndex + 1, 12));
								//	if (nLineCode == nLineCode1) {
								//		DoWork(index, taskIndex + 1, true);
								//	}

								//	g_flag = false;
								//	return true;

								//}
							}
						}
					}
				}
			}


			//CString sState = g_main_cwnd->m_list_info.GetItemText(taskIndex, 4);
			//if (sState == L"2" || sState == L"4") {
			//	DoWork(index, taskIndex + 1, true);
			//	g_main_cwnd->m_list_info.SetItemText(taskIndex, 6, L"完成");
			//	g_AccountFile.SetString(NumberToString(taskIndex + 1), L"state", L"1");
			//	Sleep(2000);
			//	DoWork(index, taskIndex + 1, true);
			//	g_flag = false;
			//	return true;
			//}


			if (jinbi == L"") {
				for (size_t i = 0; i < 10; i++)
				{
					dm->FindPic(0, 4, 443, 800, L"bagMoney.bmp", L"202020", 0.8, 0, &x, &y);
					if (x == -1) {
						//按键i打开背包
						dm->SetWindowState(g_info[index].hwnd, 12);
						dm->KeyPress(73);
						ScriptDelay(index, 1000);
						long xx, yy;

						dm->FindPic(1, 12, 539, 800, L"shuo.bmp", L"050505", 0.90, 0, &xx, &yy);
						if (xx > 0) {
							dm->MoveTo(xx + 2, yy + 2);
							dm->LeftClick();
							Sleep(1000);
						}
					}
					else
					{
						ScriptDelay(index, 1000);
						jinbi = dm->Ocr(x+58, y -3, x + 145, y + 20, L"000000-050505", 0.9);
						g_main_cwnd->AppendText(L"金币：" + jinbi);
						dm->KeyPress(27);
						break;
					}
					ScriptDelay(index, 1000);
				}
			}
			if (_wtoi(jinbi) < 1000000) {//金币小于100万直接完成
				//设置状态已完成
				g_AccountFile.SetString(NumberToString(taskIndex + 1), L"state", L"1");
				//g_AccountFile.SetString(NumberToString(taskIndex + 1), L"bbjb", jinbi);
				g_main_cwnd->m_list_info.SetItemText(taskIndex, 6, L"完成");
				g_main_cwnd->m_list_info.SetItemText(taskIndex, 9, L"背包金币"+jinbi);
				g_main_cwnd->m_list_info.SetItemText(taskIndex, 8, jinbi);
				g_AccountFile.SetString(NumberToString(taskIndex + 1), L"jiaoyi", jinbi);
				//取配置线路和列表线路比较如果不同则换线

				int nLineCode = g_IniFile.GetInt(L"Set", L"CodeLine");//当前配置线路
				int nLineCode1 = _wtoi(g_main_cwnd->m_list_info.GetItemText(taskIndex + 1, 12));
				if (nLineCode == nLineCode1) {
					DoWork(index, taskIndex + 1, true);
				}

				g_flag = false;
				return true;
				
			}
			else {
				for (size_t i = 0; i < 5; i++)
				{
					dm->FindPic(0, 4, 443, 800, L"bagMoney.bmp", L"202020", 0.8, 0, &x, &y);
					if (x > 0) {
						dm->KeyPress(27);
						break;
					}
					if (x == -1) {
						OutPutListView(taskIndex, L"未找到物品栏开始查找交易地图");
						break;
					}
					Sleep(100);
				}
				for (size_t i = 0; i < 8; i++)
				{
					//查找小地图
					for (size_t j = 0; j < 5; j++)
					{
						dm->FindPic(0, 0, 200, 200, L"miniMap.bmp", L"050505", 0.90, 0, &x, &y);
						if (x > 0) {
							break;
						}
						Sleep(100);
					}
					if (x > 0) {
						OutPutListView(taskIndex, L"开始查找交易地图");
						dm->FindPic(0, 0, 200, 200, L"jyMap1.bmp", L"050505", 0.90, 0, &x, &y);
						if (x > 0) {
							intX = x;
							intY = y;
							OutPutListView(taskIndex, L"找到交易地图");
							break;
						}
					}

					//171,618 15,51     15+x-15  51+y-51 
					ScriptDelay(index, 500);
				}
				if (x>0) {
					dm->SetWindowState(g_info[index].hwnd, 12);
					//当前为交易地图则直接交易
					//偏移点击地图
					//选区
					ScriptDelay(index, 2000);
					OutPutListView(taskIndex, L"交易初始化");

					/*if (l == 0) {
						OutPutListView(taskIndex, L"切换线路");
						ScriptDelay(index, 2000);
						dm->FindColor(778, 743, 781, 746, L"0b94d7-050505", 0.95, 0, &x, &y);
						OutPutListView(taskIndex, L"线路坐标"+NumberToString(x));
						if (x > 0) {
							ScriptDelay(index, 1000);
							dm->MoveTo(x, y);
							ScriptDelay(index, 2000);
							dm->LeftClick();
							ScriptDelay(index, 2000);
							dm->MoveTo(x, y - 163);
							ScriptDelay(index, 500);
							dm->LeftClick();
							ScriptDelay(index, 500);
						}
						
						dm->FindPic(611, 232, 695, 299, L"xq9.bmp", L"202020", 0.95, 0, &x, &y);
						if (x > 0) {
							ScriptDelay(index, 1000);
							dm->MoveTo(x+7, y+5);
							ScriptDelay(index, 500);
							dm->LeftDoubleClick();
							ScriptDelay(index, 500);
							ScriptDelay(index, 8000);
							l = 1;
						}
						dm->FindPic(611, 232, 695, 299, L"xq91.bmp", L"202020", 0.90, 0, &x, &y);
						if (x > 0) {
							ScriptDelay(index, 1000);
							dm->KeyPress(27);
							ScriptDelay(index, 1000);
							l = 1;
						}
					}*/

					for (size_t ii = 0; ii < 5; ii++)
					{
						OutPutListView(taskIndex, L"右键交易");
						dm->FindPic(16, 493, 347, 685, L"rightWnd.bmp", L"202020", 0.90, 0, &x, &y);
						if (x == -1) {
							OutPutListView(taskIndex, L"右键点击坐标"+ NumberToString (intX + (171 - intX + intX - 15))+L","+NumberToString(intY + (618 - intY + intY - 51)));
							dm->MoveTo(171, 618);
							ScriptDelay(index, 500);
							dm->RightClick();
							ScriptDelay(index, 500);
						}
						else {
							dm->MoveTo(x + 10, y + 3);
							ScriptDelay(index, 500);
							dm->LeftClick();
							ScriptDelay(index, 500);
							break;
						}
					}
					ScriptDelay(index, 1500);
					for (size_t jj = 0; jj < 5; jj++)
					{

						OutPutListView(taskIndex, L"等待交易号提供药水");
						if (runScript(index, L"jyWnd")) {
							//查找是否存在交易药水
							dm->FindPic(g_info[index].x - 100, g_info[index].y, g_info[index].x, g_info[index].y + 200, L"yaoshuiTag.bmp", L"101010", 0.9, 0, &x, &y);
							if (x > 0) {
								dm->MoveTo(g_info[index].x + 55, g_info[index].y + 208);
								dm->LeftClick();
								ScriptDelay(index, 1500);
								//dm->KeyPressStr(L"500", RandomNumber(300, 500));
								dm->SendString2(g_info[index].hwnd, jinbi);
								ScriptDelay(index, 1500);
								dm->KeyPress(13);
								ScriptDelay(index, 1500);


								#pragma region 交易药水
								//查找背包药水
								dm->FindPic(1, 12, 239, 521, L"wupinWnd.bmp", L"050505", 0.90, 0, &x, &y);
								CString strx;
								strx.Format(L"正在打开物品消耗栏坐标%d", x);
								g_main_cwnd->AppendText(strx);
								if (x > 0) {
									g_main_cwnd->AppendText(L"打开物品消耗栏");
									Sleep(1000);
									dm->MoveTo(x-5, y + 25);
									Sleep(1000);
									dm->LeftClick();
									Sleep(1000);
									dm->MoveTo(1000, RandomNumber(100, 150));
								}

								dm->FindPic(1, 12, 439, 521, L"yaoshui.bmp", L"202020", 0.90, 0, &x, &y);
								strx.Format(L"背包药水坐标%d", x);
								g_main_cwnd->AppendText(strx);
								if (x > 0) {
									g_main_cwnd->AppendText(L"找到药水位置");
									Sleep(1000);
									dm->MoveTo(x + 20, y + 10);
									Sleep(500);
									dm->LeftClick();
									Sleep(500);
									dm->MoveTo(g_info[index].x - 79 + 5 * 35, g_info[index].y + 144);//移动药水
									g_main_cwnd->AppendText(L"移动药水到交易栏");
									Sleep(1000);
									dm->LeftClick();
									dm->MoveTo(900, RandomNumber(100, 150));
								}
								Sleep(RandomNumber(3000, 5000));
								dm->FindPic(20, 156, 783, 526, L"okNumWnd.bmp", L"050505", 0.90, 0, &x, &y);
								if (x > 0) {
									g_main_cwnd->AppendText(L"找到数量窗口");
									Sleep(1000);
									dm->KeyPress(13);
									Sleep(1000);
								}
								#pragma endregion



								//交易
								dm->MoveTo(g_info[index].x + 45, g_info[index].y + 7);
								ScriptDelay(index, 500);
								dm->LeftClick();
								ScriptDelay(index, 5500);
								dm->KeyPress(13);
								ScriptDelay(index, 5500);
								dm->KeyPress(13);
								//dm->SendString2(g_info[index].hwnd, jinbi);//交易所有金币
								//置完成 小退
								g_AccountFile.SetString(NumberToString(taskIndex + 1), L"state", L"1");
								g_AccountFile.SetString(NumberToString(taskIndex + 1), L"bbjb", jinbi);
								g_main_cwnd->m_list_info.SetItemText(taskIndex, 6, L"完成");
								g_main_cwnd->m_list_info.SetItemText(taskIndex,8, jinbi);
								g_main_cwnd->m_list_info.SetItemText(taskIndex, 9, jinbi);
								//KillProcess(L"MapleStory.exe");
								//KillProcess(L"GameLauncher.exe");
								g_AccountFile.SetString(NumberToString(taskIndex + 1), L"jiaoyi", jinbi);

								//取配置线路和列表线路比较如果不同则换线
								int nLineCode = g_IniFile.GetInt(L"Set", L"CodeLine");//当前配置线路
								int nLineCode1 = _wtoi(g_main_cwnd->m_list_info.GetItemText(taskIndex + 1, 12));
								if (nLineCode == nLineCode1) {
									DoWork(index, taskIndex + 1, true);
								}

								g_flag = false;
								return true;
								//g_AccountFile.SetInt(NumberToString(taskIndex + 1), L"state", 1);

							}

						}
						OutPutListView(taskIndex, L"等待交易号提供药水.");
						ScriptDelay(index, 500);
						OutPutListView(taskIndex, L"等待交易号提供药水..");
					}
					if (runScript(index, L"jyWndNo")) {
						OutPutListView(taskIndex, L"交易未成功关闭交易");
					}
					
				}
				else {
					/*dm->SetWindowState(g_info[index].hwnd, 12);
					OutPutListView(taskIndex, L"等待进入交易地图");*/

					///dm->LeftClick();
					//查找按键图是否存在 不存在按键b 存在则点击
					ScriptDelay(index,500);
					for (size_t i = 0; i < 5; i++)
					{
						dm->FindPic(702, 500, 850, 597, L"setting.bmp", L"050505", 0.90, 0, &x, &y);
						if (x > 0) {
							dm->KeyPress(27);
							ScriptDelay(index, 300);
						}
						dm->FindPic(119, 52, 732, 294, L"bTag.bmp", L"202020", 0.90, 0, &x, &y);
						if (x == -1)
						{
							dm->KeyPress(66);
						}
						else {
							dm->MoveTo(x + 20, y + 3);
							ScriptDelay(index, 300);
							dm->LeftClick();
						}
						ScriptDelay(index, 300);
					}
					
					for (size_t i = 0; i < 5; i++)
					{
						dm->FindPic(369, 326, 672, 464, L"okWnd.bmp|okWnd1.bmp", L"202020", 0.90, 0, &x, &y);
						if (x > 0) {
							dm->MoveTo(x + 10, y + 3);
							ScriptDelay(index, 300);
							dm->LeftClick();
						}
						ScriptDelay(index, 1000);
					}

					for (size_t i = 0; i < 5; i++)
					{
						dm->FindPic(119, 52, 732, 294, L"bTag1.bmp", L"202020", 0.90, 0, &x, &y);
						if (x > 0) {
							ScriptDelay(index, 500);
							dm->KeyPress(27);
						}
						ScriptDelay(index, 3000);
					}

				}
				
			}
		}
		else if(g_AccountFile.GetInt(NumberToString(taskIndex + 1), L"state") == 0 && g_main_cwnd->m_trade.GetCheck() == 0){//状态未完成执行任务 并且交易未选中

			for (size_t i = 0; i < 5; i++)
			{
				dm->FindPic(0, 3, 218, 173, L"jyMap1.bmp", L"202020", 0.9, 0, &x, &y);
				if (x>0) {
					ScriptDelay(index, 1000);
					dm->KeyPress(38);
					ScriptDelay(index, 1000);
				}
				ScriptDelay(index, 1000);
			}
			dm->FindPic(0, 0, 283, 227, L"taskRun.bmp|mapB1.bmp", L"050505", 1, 0, &x, &y);
			if (runScript(index, L"taskRun") || x > 0) {//如果在村庄
				//打开boss地图
				ScriptDelay(index, 1000);
				dm->KeyPress(69);
				ScriptDelay(index, 1000);
				if (bCheckArms) {
					for (int i = 0; i < 3; i++)
					{
						dm->FindPic(0, 0, 1024, 768, L"zhuangWnd.bmp", L"303030", 0.80, 0, &x, &y);
						if (x > 0) {
							ScriptDelay(index,500);
							CString str = dm->FindPicExS(x,y, x + 208, y + 206, L"armsNull.bmp|armsNull1.bmp|armsNull2.bmp", L"202020", 0.9, 0);
							//AfxMessageBox(str);
							if (str != L"") {
								bCheckArms = false;
							}
							break;
						}
						ScriptDelay(index,300);
					}
					moveKey(index, 27, 500);
				}
				dm->KeyPress(84);
				ScriptDelay(index,1000);
				if (runScript(index,L"taskchose2")) {
					Sleep(1000);
					dm->MoveTo(g_info[index].x + 92, g_info[index].y + 260);
					dm->LeftClick();
				}
			}
			if (runScript(index,L"taskGameOver")) {

				Sleep(100);
				moveKey(index,27, 200);
				Sleep(1000);
				g_AccountFile.SetString(NumberToString(taskIndex + 1), L"state", L"6");
				g_main_cwnd->m_list_info.SetItemText(taskIndex, 6, L"Boss已完成");

			}
			//检查装备
			//if(检查装备） 不存在则结束游戏


			//扎昆地图
			dm->FindPic(0, 0, 510, 400, L"mapS2.bmp", L"050505", 1, 0, &x, &y);
			if (x > 0) {
				long x1, y1;
				dm->FindPic(0, 0, 1017, 673, L"bagWnd.bmp|bagWnd1.bmp", L"000000", 1, 0, &x1, &y1);
				if (x1 > 0) {
					dm->KeyPress(73);
				}
				dm->KeyDown(37);
				Sleep(100);
				for (size_t i = 0; i < 20; i++)
				{
					dm->KeyPress(38);
					Sleep(RandomNumber(80, 120));
				}
				Sleep(RandomNumber(2000, 2500));
				dm->FindPic(0, 0, 510, 400, L"mapS2.bmp", L"050505", 1, 0, &x, &y);
				if (x > 0) {
					dm->KeyUp(37);
					dm->KeyUp(38);
					Sleep(400);
					dm->KeyDown(39);
					for (size_t i = 0; i < 20; i++)
					{
						dm->KeyPress(38);
						Sleep(RandomNumber(80, 120));
					}
					Sleep(RandomNumber(1000, 1500));

				}
				dm->KeyUp(39);
				dm->KeyUp(38);
			}

			//退出扎昆
			dm->FindPic(0, 0, 510, 400, L"mapS1.bmp", L"050505", 1, 0, &x, &y);
			if (x > 0) {
				if (movetoX(index, 115)) {
					dm->MoveTo(x + 10, y - RandomNumber(20, 30));
					Sleep(1500);

				}
				for (size_t i = 0; i < 5; i++)
				{
					//dm->MoveTo(x + 10, y - RandomNumber(3, 8));

					//Sleep(1000);
					dm->FindPic(0, 0, 1024, 700, L"npcS2.bmp", L"101010", 1, 0, &x, &y);
					if (x > 0) {
						dm->MoveTo(x + 10, y - RandomNumber(20, 30));
						dm->LeftClick();
						Sleep(1500);
						dm->FindPic(0, 0, 1000, 700, L"exitZk.bmp", L"050505", 1, 0, &x, &y);
						if (x > 0) {
							dm->MoveTo(x + 10, y + RandomNumber(3, 8));
							dm->LeftClick();
							Sleep(1000);
							for (size_t k = 0; k < 5; k++)
							{
								dm->FindPic(639, 375, 791, 466, L"next1.bmp", L"050505", 1, 0, &x, &y);
								if (x > 0) {
									dm->KeyPress(32);
									//dm->MoveToEx(x, y, 5, 5);
									//dm->LeftClick();
									////dm->KeyPress(32);
									//dm->MoveTo(x - RandomNumber(100, 200), y);
									Sleep(RandomNumber(1000, 1100));
									
								}
								Sleep(100);

							}

						}
					}
				}
			}

			
			//dm->FindPic(800, 0, 1024, 50, L"red.bmp", L"101010", 0.9, 0, &x, &y);
			//if (x > 0 && findpic) {
			//	moveKey(index, 27, 200);
			//}
			if (findpic) {
				dm->FindPic(800, 0, 1024, 50, L"red.bmp", L"101010", 0.9, 0, &x, &y);
				if (x > 0) {
					moveKey(index, 27, 200);
				}
				dm->FindPic(189, 132, 889, 479, L"yellwo.bmp", L"101010", 0.9, 0, &x, &y);
				if (x > 0 || g_main_cwnd->m_list_info.GetItemText(taskIndex, 11).GetLength() > 0) {
					moveKey(index, 27, 200);
				}
				dm->FindPic(89, 63, 929, 408, L"cp.bmp", L"101010", 0.9, 0, &x, &y);
				if (x > 0)
				{
					moveKey(index, 27, 200);
				}

			}
			if (!findpic) {

				dm->FindPic(800, 0, 1024, 50, L"red.bmp", L"101010", 0.9, 0, &x, &y);
				if (x > 0) {
					g_main_cwnd->m_list_info.SetItemText(taskIndex, 10, L"红电脑");
					findpic = true;
				}
				for (size_t i = 0; i < 5; i++)
				{
					CString taskStr = L"loginOkWnd|closeWnd|closeWnd1|closeWnd4";
					runScriptList(index, taskStr);
					dm->FindColor(770, 730, 774, 737, L"23aae2", 0.98, 0, &x, &y);
					if (x > 0) {
						dm->MoveTo(x, y);
						Sleep(1000);
						dm->LeftClick();
						Sleep(1000);
						dm->MoveTo(x, y - 98);
						Sleep(1000);
						dm->LeftClick();
						Sleep(1000);
						for (size_t j = 0; j < 5; j++)
						{
							CString taskStr = L"loginOkWnd|closeWnd|closeWnd1|closeWnd4";
							runScriptList(index, taskStr);

							//dm->FindPic(189, 132, 889, 479, L"yellwo.bmp", L"101010", 0.9, 0, &x, &y);
						
							dm->FindPic(189, 132, 889, 479, L"yellwobi.bmp", L"050505", 0.98, 0, &x, &y);
							if (x > 0) {
								g_main_cwnd->m_list_info.SetItemText(taskIndex, 10, L"50%-");
								findpic = true;
								i = 5;
								moveKey(index, 27, 200);
								break;
							}
							
							if (g_main_cwnd->m_list_info.GetItemText(taskIndex, 11).GetLength() > 0)
							{
								findpic = true;
							}
							
							Sleep(1000);
						}

						findpic = true;
					}
					dm->FindPic(89, 63, 929, 408, L"cp.bmp", L"101010", 0.9, 0, &x, &y);
					if (x > 0)
					{
						break;
					}
				}


			}



			g_main_cwnd->AppendText(L"当前状态:" + g_AccountFile.GetString(NumberToString(taskIndex + 1), L"state"));
			if (g_AccountFile.GetString(NumberToString(taskIndex + 1), L"state") == L"0"&& runScript(index,L"taskNpc") ) {//查找任务npc如果找不到向右移动
				ScriptDelay(index, 2000);
				runScript(index,L"taskChoseOne");
				ScriptDelay(index, 2000);
				OutPutListView(taskIndex, L"1");
				runScript(index, L"taskChoseNext");
				dm->MoveTo(RandomNumber(100, 200), RandomNumber(200, 300));
				ScriptDelay(index, 500);
				OutPutListView(taskIndex, L"2");
				runScript(index,L"taskChoseNext");
				ScriptDelay(index, 2000);
				if (runScript(index,L"taskReady")) {
					while (g_flag)
					{
						OutPutListView(taskIndex, L"等待组队.");
						if(runScript(index, L"taskTeamWaitOk")) {
							dm->MoveTo(100, RandomNumber(200, 300));
							OutPutListView(taskIndex, L"等待组队..");
						}

						if(runScript(index,L"taskBossYes") || runScript(index, L"bossEnd")){
							g_bloodState = true;
							//记录数量
							if (k == 0) {
								int num = g_AccountFile.GetInt(NumberToString(taskIndex + 1), L"num");
								num++;
								g_AccountFile.SetInt(NumberToString(taskIndex + 1), L"num",num);
								
								k = 1;
							}
							dm->KeyPress(229);
							//按1键
							bossAttack(index, taskIndex);

							if (runScript(index, L"bossEnd"))
							{
								//显示数量
								g_main_cwnd->m_list_info.SetItemText(taskIndex,7, g_AccountFile.GetString(NumberToString(taskIndex + 1), L"num"));
								k = 0;//boss任务结束记录数量标记为0
								OutPutListView(taskIndex, L"boss任务结束");
								dm->KeyPress(13);
								for (size_t i = 0; i < 100; i++)
								{
									//查找退出路口
									moveKey(index, 39, 400);
									ScriptDelay(index,1000);
									OutPutListView(taskIndex, L"查找出口");
									if (runScript(index, L"taskBossEndOut")) {

										if (g_info[index].x >= 985 && g_info[index].x < 999) {
											OutPutListView(taskIndex, L"点击出口");
											dm->KeyPress(38);
											moveKey(index, 38, 200);
										}
										else {
											moveKey(index, 37, 500);
											dm->KeyPress(38);
											moveKey(index, 38, 200);
										}
									}
									if (runScript(index, L"taskNpcTag")) {
										break;
									}
									if (i > 50) {
										if (!runScript(index, L"taskBossYes")) {
											break;
										}
									}

								}
								g_bloodState = false;
								break;
							}
						}

					}
				}

			}
			else {
				OutPutListView(taskIndex, L"移动查找bossNpc!");
				dm->FindPic(0, 0, 283, 227, L"mapB.bmp", L"050505", 1, 0, &x, &y);
				if (x == -1) {
					dm->delay(500);
					dm->KeyDown(39);
					dm->delay(2000);
					dm->delay(500);
					dm->KeyUp(39);
				}
			}

		}
		//查找boss
		//TRACE(L"开始任务");
		//ScriptDelay(index, 1000);
	}
	return true;
}









void OutPutListView(int nIndex, CString str) {
	g_main_cwnd->m_list_info.SetItemText(nIndex, 5, str);
}

//void blood(int nIndex) {
//	if (g_dm->GetColor(545, 712) == L"f0f0f0") {
//		if (g_dm->GetColor(567, 720) == L"9e9da0") {
//			g_main_cwnd->AppendText(L"补血");
//			dm->KeyPress(35);
//		}
//	}
//	else {
//		if (g_dm->GetColor(567, 736) == L"9e9da0") {
//			g_main_cwnd->AppendText(L"补血");
//			g_dm->KeyPress(35);
//		}
//	}
//}

bool ChangeLine(CString strLine) {
	//查找迅游窗口是否存在 不存在则启动迅游
	long x, y, x1, y1;
	long hwnd = g_dm->FindWindowW(L"XunYouMainClass_4B32", L"迅游国际版");
	if (hwnd == 0) {
		g_dm->RunApp(L"D:\\Program Files (x86)\\XunYou_Intl\\xunyou.exe", 0);
		Sleep(5000);
		for (size_t i = 0; i < 15; i++)
		{
			g_dm->FindPic(0, 0, 1280, 960, L"xytag.bmp", L"050505", 0.95, 0, &x, &y);
			if (x > 0) {
				hwnd = g_dm->FindWindowW(L"XunYouMainClass_4B32", L"迅游国际版");
				break;
			}
			Sleep(1000);
		}
	}
	g_dm->SetWindowState(hwnd, 12);
	g_dm->UnBindWindow();
	int ret = g_dm->BindWindowEx(hwnd, L"normal", L"normal", L"normal", L"normal", 0);
	g_dm->SetDict(2, L"line.txt");
	g_dm->UseDict(2);
	if (ret > 0) {
		for (size_t i = 0; i < 5; i++)
		{
			//g_dm->BindWindowEx(hwnd, L"normal", L"normal", L"normal", L"normal", 0);
			//识别迅游窗口内线路是否是需要连接的线路
			g_dm->FindPic(0, 0, 1280, 960, L"startnet.bmp|nostartnet.bmp", L"050505", 0.95, 0, &x, &y);
			CString str;
			if (x > 0) {
				str = g_dm->Ocr(x-100, y, x+240, y+230, L"bbbbbb-666666", 1);
			}
			
			//CString str = g_dm->Ocr(x3 - 188, y3 + 10, x3, y3 + 200, L"bbbbbb-555555", 1);
			//g_main_cwnd->AppendText(L"识别数据:" + str);

			if (str == strLine) {//如果迅游窗口内的线路为需要的线路则直接启动线路
				g_dm->FindPic(0, 0, 1280, 960, L"startnet.bmp", L"050505", 0.95, 0, &x, &y);
				if (x > 0) {//启动成功后返回
					return true;
				}
				g_dm->FindPic(0, 0, 1280, 960, L"nostartnet.bmp", L"050505", 0.95, 0, &x, &y);
				if (x > 0) {//找到线路后启动线路
					g_dm->MoveTo(x, y);
					g_dm->LeftClick();
					Sleep(5000);
					return true;
				}
			}
			else {
				Sleep(1000);
				g_dm->UnBindWindow();
				g_dm->SetDict(2, L"line.txt");
				g_dm->UseDict(2);
				//查找所需的线路并点击选中线路
				g_dm->FindPic(0, 0, 1280, 960, L"startnet.bmp", L"050505", 0.95, 0, &x1, &y1);
				if (x1 > 0) {//未识别到线路已经启动线路则先关闭线路
					g_main_cwnd->AppendText(L"网络已连接关闭网络");
					g_dm->MoveTo(x1 + 33, y1 - 32);
					g_dm->LeftClick();
					Sleep(5000);
				}
				g_dm->FindPic(0, 0, 1280, 960, L"nostartnet.bmp", L"050505", 0.95, 0, &x1, &y1);
				if (x1 > 0) {
					g_dm->FindPic(0, 0, 1280, 960, L"netlist.bmp", L"050505", 0.9, 0, &x, &y);
					if (x == -1) {
						g_main_cwnd->AppendText(L"网络未连接");
						g_dm->MoveTo(x1 + 67, y1 + 85);
						g_dm->LeftClick();
						Sleep(2000);
					}
				}
				//查找线路列表是否开启
				g_dm->FindPic(0, 0, 1280, 960, L"netlist.bmp", L"050505", 0.9, 0, &x, &y);
				if (x > 0) {
					g_dm->MoveTo(x-148, y + 39);
					g_dm->LeftClick();
					Sleep(3000);
					g_dm->MoveTo(x, y + 88);
					g_dm->LeftClick();
					Sleep(2000);
					long x3=x, y3=y;
					for (size_t i = 0; i < 100; i++)
					{
						str = g_dm->Ocr(x3 - 188, y3 + 10, x3, y3 + 200, L"bbbbbb-555555", 1);
						//CString str = g_dm->Ocr(x3 - 188, y3 + 10, x3, y3 + 200, L"bbbbbb-555555", 1);
						g_main_cwnd->AppendText(strLine+L"识别数据2:" + str);
						g_dm->FindStrFast(x3-188, y3+10, x3, y3+200, strLine, L"bbbbbb-555555", 1, &x, &y);
						if (x > 0) {//找到线路并点击
							g_dm->MoveTo(x, y);
							g_dm->LeftClick();
							Sleep(2000);
							g_dm->FindPic(0, 0, 1280, 960, L"nostartnet.bmp", L"050505", 0.95, 0, &x1, &y1);
							if (x1 > 0) {
								g_dm->MoveTo(x1, y1);
								g_dm->LeftClick();
								Sleep(10000);
								g_dm->BindWindowEx(hwnd, L"normal", L"normal", L"normal", L"normal", 0);
								//识别迅游窗口内线路是否是需要连接的线路
								str = g_dm->Ocr(52, 444, 207, 470, L"bbbbbb-555555", 1);
								//CString str = g_dm->Ocr(x3 - 188, y3 + 10, x3, y3 + 200, L"bbbbbb-555555", 1);
								g_main_cwnd->AppendText(L"识别数据1:" + str);
								if (str == strLine)
								{
									g_dm->SetWindowState(hwnd, 2);
									return true;
								}
							}
							break;
						}
						g_dm->WheelDown();
						Sleep(700);
					}//未找到关闭线路列表重新打开
					g_dm->FindPic(0, 0, 1280, 960, L"startnet.bmp", L"050505", 0.95, 0, &x1, &y1);
					if (x1 > 0) {//未识别到线路已经启动线路则先关闭线路
						g_dm->MoveTo(x1 + 33, y1 - 32);
						g_dm->LeftClick();
						Sleep(5000);
					}
					g_dm->FindPic(0, 0, 1280, 960, L"nostartnet.bmp", L"050505", 0.95, 0, &x, &y);
					g_dm->MoveTo(x + 67, y + 85);
					g_dm->LeftClick();
				}
				else {
					g_dm->FindPic(0, 0, 1280, 960, L"nostartnet.bmp", L"050505", 0.95, 0, &x, &y);
					if (x > 0) {
						g_dm->MoveTo(x + 67, y +85);
						g_dm->LeftClick();
						Sleep(1000);
					}
				}
			}
		}
	}
	//查找是否已经启动线路，启动则先关闭线路


	

	//检查线路是否关闭，关闭后打开线路列表

	//查找线路找到后选择线路

	//选中线路后查询迅游窗口是否选中正确的线路如果正确则点击开启加速器 

	//查找线路是否启动成功，成功则返回

	return false;
}

bool movetoX1(long nTagX) {

	long nMapX, nMapY, x, y, nX, nPath;
	int j = 0;
	g_dm->KeyUp(37);
	g_dm->KeyUp(39);
	g_dm->FindPic(0, 0, 200, 200, L"miniMap.bmp", L"050505", 0.9, 0, &nMapX, &nMapY);
	g_dm->FindPic(0, 0, 400, 250, L"localTag.bmp|localTag1.bmp|localTag2.bmp|localTag3.bmp|localTag4.bmp", L"050505", 0.9, 0, &x, &y);

	for (size_t i = 0; i < 10; i++)
	{
		g_dm->FindPic(0, 0, 400,300, L"localTag.bmp|localTag1.bmp|localTag2.bmp|localTag3.bmp|localTag4.bmp", L"050505", 0.9, 0, &x, &y);
		if (x == -1) {
			return false;
		}
		nX = x - nMapX;
		
		if (abs(nX - nTagX) <= 1) {
			g_dm->KeyUp(39);
			g_dm->KeyUp(37);
			Sleep(500);
			return true;
		}
		if (nX - nTagX >1) {//往左移动
			g_dm->KeyDown(37);
			for (size_t i = 0; i < 100; i++)
			{
				g_dm->FindPic(0, 0, 400, 250, L"localTag.bmp|localTag1.bmp|localTag2.bmp|localTag3.bmp|localTag4.bmp", L"050505", 0.9, 0, &x, &y);
				nX = x - nMapX;
				CString s;
				s.Format(L"%d,%d", i, nX);
				g_main_cwnd->AppendText(s);
				if (nX - nTagX == 0) {
					
					g_dm->KeyUp(39);
					g_dm->KeyUp(37);
					//g_dm->KeyPress(39);
					Sleep(500);
					return true;
				}
				if (abs(nX - nTagX) <= 1) {
					
					g_dm->KeyUp(39);
					g_dm->KeyUp(37);

					g_dm->FindPic(0, 0, 400, 250, L"localTag.bmp|localTag1.bmp|localTag2.bmp|localTag3.bmp|localTag4.bmp", L"050505", 0.9, 0, &x, &y);
					nX = x - nMapX;
					nPath = nX - nTagX;
					//g_dm->KeyPress(39);
					Sleep(500);
					break;
				}
				if (abs(nX - nTagX) <= 3) {
					g_dm->KeyUp(37);
					g_dm->KeyDown(37);
					Sleep(50);
					g_dm->KeyUp(37);
				}
				Sleep(10);
			}
			g_dm->KeyUp(37);
		}
		if (nX - nTagX < -1) {
			g_dm->KeyDown(39);
			for (size_t i = 0; i < 100; i++)
			{
				g_dm->FindPic(0, 0, 400, 250, L"localTag.bmp|localTag1.bmp|localTag2.bmp|localTag3.bmp|localTag4.bmp", L"050505", 0.9, 0, &x, &y);
				nX = x - nMapX;
				CString s;
				s.Format(L"%d,%d", i, nX);
				g_main_cwnd->AppendText(s);
				if (nX - nTagX == 0) {
					
					g_dm->KeyUp(39);
					g_dm->KeyUp(37);
					//g_dm->KeyPress(37);
					Sleep(500);
					return true;
				}
				if (abs(nX - nTagX) <= 1) {
					g_dm->KeyUp(37);
					g_dm->KeyUp(39);
					g_dm->FindPic(0, 0, 400, 250, L"localTag.bmp|localTag1.bmp|localTag2.bmp|localTag3.bmp|localTag4.bmp", L"050505", 0.9, 0, &x, &y);
					nX = x - nMapX;

					//g_dm->KeyPress(37);
					Sleep(100);
					break;
				}
				if (abs(nX - nTagX) <= 3) {
					g_dm->KeyUp(39);
					g_dm->KeyDown(39);
					Sleep(50);
					g_dm->KeyUp(39);
				}
				Sleep(10);
			}
			g_dm->KeyUp(39);
		}
	}
	return false;
}


bool movetoX(long index,long nTagX) {
	dmsoft *dm = g_info[index].dm;
	long nMapX, nMapY, x, y, nX, nPath;
	int j = 0;
	dm->KeyUp(37);
	dm->KeyUp(39);
	dm->FindPic(0, 0, 600, 600, L"miniMap.bmp", L"050505", 0.9, 0, &nMapX, &nMapY);
	for (size_t i = 0; i < 10; i++)
	{
		//closeWndTask();

		//}
		//while (true)
		//{
		dm->FindPic(0, 0, 600, 600, L"localTag.bmp|localTag1.bmp|localTag2.bmp|localTag3.bmp|localTag4.bmp", L"050505", 0.9, 0, &x, &y);
		nX = x - nMapX;
		nPath = nX - nTagX;
		if (nX - nTagX == 0) {
			dm->KeyUp(39);
			dm->KeyUp(37);
			return true;
		}
		dm->FindPic(0, 0, 1000, 700, L"wndClose.bmp", L"050505", 0.9, 0, &x, &y);
		if (x > 0) {  
			dm->KeyUp(39);
			dm->KeyUp(37);
			return true;
		}
		if (nX - nTagX >= 2) {//往左移动
			dm->KeyDown(37);
			for (size_t i = 0; i < 200; i++)
			{
				dm->FindPic(0, 0, 600, 600, L"localTag.bmp|localTag1.bmp|localTag2.bmp|localTag3.bmp|localTag4.bmp", L"050505", 0.9, 0, &x, &y);
				nX = x - nMapX;
				//CString str;
				//str.Format(L"相距坐标%d", abs(nX - nTagX));
				//this->AppendText(str);
				Sleep(50);
				if (nX - nTagX == 0) {
					dm->KeyUp(37);
					return true;
				}
				if (abs(nX - nTagX) <= 1 || nX - nTagX < -1) {
					dm->KeyUp(37);
					return true;
				}
				dm->FindPic(0, 0, 1000, 700, L"wndClose.bmp", L"050505", 0.9, 0, &x, &y);
				if (x > 0) {
					dm->KeyUp(37);
					return true;
				}

			}
			dm->KeyUp(37);
			//if (abs(nX - nTagX) <= 1 || nX - nTagX < -2) {
			//	break;
			//}
		}
		if (nX - nTagX <= -2) {
			dm->KeyDown(39);
			for (size_t i = 0; i < 200; i++)
			{

				dm->FindPic(0, 0, 600, 600, L"localTag.bmp|localTag1.bmp|localTag2.bmp|localTag3.bmp|localTag4.bmp", L"050505", 0.9, 0, &x, &y);
				nX = x - nMapX;
				//Sleep(10);
				if (nX - nTagX == 0) {
					dm->KeyUp(39);
					return true;
				}
				if (abs(nX - nTagX) <= 1 || nX - nTagX > 1) {
					dm->KeyUp(39);
					return true;
				}
				Sleep(50);
				dm->FindPic(0, 0, 1000, 700, L"wndClose.bmp", L"050505", 0.9, 0, &x, &y);
				if (x > 0) {
					dm->KeyUp(39);
					return true;
				}
			}
			dm->KeyUp(39);
			//if (abs(nX - nTagX) <= 1 || nX - nTagX > 2) {
			//	break;
			//}
		}
		//if (nPath == nX - nTagX) {
		//	j++;
		//}
		//if (j > 3) {
		//	return false;
		//}
	}
	if (abs(nX - nTagX) <= 1) {
		return true;
	}
	return false;
}




//交易
void Trade(long index,int taskIndex) {





	////丢掉物品
	//strZb = dm->FindPicEx(50, 50, 500, 600, L"wupinhj.bmp|wupinrj.bmp", L"202020", 0.9, 0);
	//arrZb.RemoveAll();
	//StringSplit(strZb, arrZb, '|');
	//if (arrZb.GetCount() > 0) {
	//	for (size_t j = 0; j < arrZb.GetCount(); j++)
	//	{
	//		long nX1, nX2, nY1, nY2;
	//		CString strPoint = arrZb.GetAt(j);
	//		CStringArray arrPoint;
	//		StringSplit(strPoint, arrPoint, ',');
	//		nX1 = _wtoi(arrPoint.GetAt(1));
	//		nY1 = _wtoi(arrPoint.GetAt(2));
	//		dm->MoveToEx(nX1 + 10, nY1 + 10, 20, 10);
	//		Sleep(RandomNumber(380, 520));
	//		dm->LeftClick();
	//		Sleep(RandomNumber(380, 520));
	//		dm->MoveToEx(300, 30, 100, 20);
	//		Sleep(RandomNumber(380, 520));
	//		dm->LeftClick();
	//		Sleep(RandomNumber(380, 520));
	//	}
	//}





	CDm *dm = g_info[index].dm;
	long x, y;
	long hwnd = dm->FindWindow(L"MapleStoryClass", L"MapleStory");
	dm->SetDict(0, L"jinbi.txt");
	dm->UseDict(0);
	int n_State = 0;
	bool isDiu = false;
	CString strWupin = L"";
	bool bBu = false;
	bool bStamp = false;
	for (size_t j = 0; j < 15; j++)
	{
		if (n_State == 0) {//切换线路
			


			dm->FindPic(558, 384, 938, 643, L"huanxian.bmp", L"202020", 0.95, 0, &x, &y);
			if (x == -1) {
				dm->KeyPress(27);
				Sleep(RandomNumber(200, 300));
			}
			else {
				Sleep(RandomNumber(200, 300));
				dm->KeyPress(13);
				Sleep(RandomNumber(200, 300));
			}
			dm->FindPic(611, 232, 695, 299, L"xq9.bmp", L"202020", 0.95, 0, &x, &y);
			if (x > 0) {
				Sleep(1000);
				dm->MoveTo(x + 7, y + 5);
				Sleep(500);
				dm->LeftDoubleClick();
				Sleep(500);
				Sleep(8000);
				n_State = 1;
			}
			dm->FindPic(611, 232, 695, 299, L"xq91.bmp", L"202020", 0.90, 0, &x, &y);
			if (x > 0) {
				Sleep(1000);
				dm->KeyPress(27);
				Sleep(1000);
				n_State = 1;
			}
		}
		
		if (n_State == 1) {//开始交易
						   //dm->FindPic(0, 0, 1024, 700, L"ckTag.bmp", L"101010", 1, 0, &x, &y);
						   //if (x > 0) {
						   //	Sleep(RandomNumber(1500, 2000));
						   //	//dm->KeyPress(27);
						   //	dm->MoveToEx(x + 10, y - 55, 10, 3);
						   //	Sleep(RandomNumber(100, 200));
						   //	dm->LeftClick();
						   //	Sleep(RandomNumber(100, 200));
						   //}

			if (!isDiu) {
				Sleep(RandomNumber(1500, 2000));
				dm->KeyPressChar(L"i");
				Sleep(RandomNumber(300, 500));
				//dm->FindPic(0, 0, 1024, 700, L"bagWnd.bmp", L"101010", 1, 0, &x, &y);
				if (dm->RunScript(L"背包线",&x,&y)) {
					dm->MoveTo(x + 40 + RandomNumber(1, 8), y + 5 + RandomNumber(2, 5));
					Sleep(RandomNumber(180, 320));
					dm->LeftClick();
					dm->MoveTo(x + 540 + RandomNumber(1, 80), y + 5 + RandomNumber(2, 50));
					Sleep(RandomNumber(1680, 2720));
					CString strZb = dm->FindPicEx(1, 1, 500, 600, L"wupinhj.bmp|wupinrj.bmp", L"202020", 0.9, 0);
					CStringArray arrZb;
					StringSplit(strZb, arrZb, '|');
					strWupin = dm->FindPicS(10,10,800,600,L"bagBiao.bmp|bagDan.bmp|buJian.bmp|buJian1.bmp",L"202020",0.9,0,&x,&y);
					//查找补东西物品
					if (arrZb.GetCount() > 0) {
						for (size_t j = 0; j < arrZb.GetCount(); j++)
						{
							long nX1, nX2, nY1, nY2;
							if (dm->RunScript(L"确定"))
								dm->KeyPressChar(L"enter");
							CString strPoint = arrZb.GetAt(j);
							CStringArray arrPoint;
							StringSplit(strPoint, arrPoint, ',');
							nX1 = _wtoi(arrPoint.GetAt(1));
							nY1 = _wtoi(arrPoint.GetAt(2));
							dm->MoveToEx(nX1 + 10, nY1 + 10, 5, 10);
							Sleep(RandomNumber(1500, 2000));
							if (dm->RunScript(L"红卷")) {
								continue;
							}
							dm->LeftClick();
							Sleep(RandomNumber(380, 520));
							dm->MoveToEx(300, 30, 100, 20);
							Sleep(RandomNumber(380, 520));
							dm->LeftClick();
							Sleep(RandomNumber(500, 800));
							if (dm->RunScript(L"确定"))
								dm->KeyPressChar(L"enter");
							Sleep(RandomNumber(1000, 1520));
						}
					}
					dm->KeyPressChar(L"i");
					Sleep(RandomNumber(380, 520));
				}
				Sleep(RandomNumber(1500, 2000));
				isDiu = true;
			}

			if(isDiu&&!bBu){
				if (strWupin == L"") {
					bBu = true;
				}
				else {
					g_main_cwnd->AppendText(L"找到的物品：" + strWupin);
					bBu = BuZhuang(index, taskIndex, strWupin);
				}
			}

			if (!bStamp) {
				if (g_main_cwnd->m_zhaKunYou.GetCheck() == 1) {
					bStamp = ZkYouPiao(index, taskIndex);
				}
			}
			if (dm->RunScript(L"猎人窗口"))
			{
				dm->KeyPressChar(L"n");
			}
			dm->RunScript(L"确定");

			if (dm->RunScript(L"买卖窗口", &x, &y)) {
				Sleep(RandomNumber(500, 1000));
				dm->Click(x + 100, y + 45, 20, 5);
			}

			//交易窗口是否打开
			long nX, nY;
			dm->FindPic(0, 0, 1024, 700, L"jyWnd.bmp|jyWnd1.bmp|jyWnd2.bmp", L"101010", 1, 0, &nX, &nY);
			if (nX > 0) {//交易窗口
				Sleep(300);
				dm->FindPic(0, 0, 500, 700, L"kuoda.bmp", L"101010", 1, 0, &x, &y);
				if (x > 0) {//窗口为小窗口
					Sleep(300);
					dm->FindPic(0, 0, 1024, 700, L"bagWnd.bmp", L"101010", 1, 0, &x, &y);
					if (x > 100) {//移动背包窗口
						dm->MoveToEx(x, y, 5, 5);
						dm->LeftDown();
						Sleep(RandomNumber(380, 550));
						dm->MoveTo(RandomNumber(90, 111), y);
						Sleep(RandomNumber(280, 350));
						dm->LeftUp();
						Sleep(RandomNumber(180, 350));
					}
				}
				//交易窗口存在 则检查窗口是否扩大
				dm->FindPic(0, 0, 500, 700, L"suoxiao.bmp", L"101010", 1, 0, &x, &y);
				if (x > 0) {//缩小背包
					dm->MoveToEx(x + 1, y + 2, 5, 5);
					dm->LeftClick();
					Sleep(RandomNumber(80, 120));
				}
				else {
					Sleep(RandomNumber(1000, 1100));
					CString strJy = dm->FindPicEx(385, 277, 565, 439, L"bagKuang.bmp", L"202020", 1, 0);
					CStringArray arrJy;
					StringSplit(strJy, arrJy, '|');

					dm->FindPic(0, 0, 1024, 700, L"bagWnd.bmp", L"101010", 1, 0, &x, &y);
					if (x > 0) {//获取背包坐标
						dm->MoveToEx(x - 40, y + 23, 5, 5);
						dm->LeftClick();
						Sleep(RandomNumber(180, 220));
						dm->MoveToEx(x - 40, y - 80, 55, 25);
						Sleep(RandomNumber(80, 120));
						Sleep(RandomNumber(1680, 2720));
						//查找装备栏装备
						//dm->FindPic(x - 70, y, x + 140, y + 300, L"ckTag.bmp", L"101010", 1, 0, &x, &y);
						if (x > 0) {//移动到交易栏
									//交易金币
							CString strZb = dm->FindPicEx(x - 70, y, x + 140, y + 300, L"card1.bmp|card2.bmp|mofang.bmp|card3.bmp", L"202020", 0.9, 0);
							CStringArray arrZb;
							StringSplit(strZb, arrZb, '|');
							for (size_t i = 0; i < arrJy.GetCount(); i++)
							{
								if (i >= arrZb.GetCount()) {
									break;
								}
								//取装备坐标栏目坐标
								long nX1, nX2, nY1, nY2;
								CString strPoint = arrZb.GetAt(i);
								CStringArray arrPoint;
								StringSplit(strPoint, arrPoint, ',');
								nX1 = _wtoi(arrPoint.GetAt(1));
								nY1 = _wtoi(arrPoint.GetAt(2));
								strPoint = arrJy.GetAt(i);
								arrPoint.RemoveAll();
								StringSplit(strPoint, arrPoint, ',');
								nX2 = _wtoi(arrPoint.GetAt(1));
								nY2 = _wtoi(arrPoint.GetAt(2));
								Sleep(RandomNumber(80, 120));
								dm->MoveToEx(nX1 + 10, nY1 + 10, 5, 10);
								Sleep(RandomNumber(580, 720));
								dm->LeftClick();
								Sleep(RandomNumber(480, 620));
								dm->MoveToEx(nX2 + 10, nY2 + 10, 5, 10);
								Sleep(RandomNumber(580, 620));
								dm->LeftClick();
								Sleep(RandomNumber(1500, 1720));
							}

							Sleep(RandomNumber(1680, 2720));

							strZb = dm->FindPicEx(x - 70, y, x + 140, y + 300, L"card1.bmp|card2.bmp|mofang.bmp|card3.bmp", L"202020", 0.9, 0);
							arrZb.RemoveAll();
							StringSplit(strZb, arrZb, '|');
							strJy = dm->FindPicEx(385, 277, 565, 439, L"bagKuang.bmp", L"202020", 1, 0);
							arrJy.RemoveAll();
							StringSplit(strJy, arrJy, '|');



							if (arrZb.GetCount() == 0) {//装备栏物品已移动执行卡片切换
								if (dm->RunScript(L"背包线", &x, &y)) {//背包坐标
									
									Sleep(RandomNumber(180, 220));
									dm->MoveToEx(x +70, y +5, 5, 5);
									Sleep(RandomNumber(180, 220));
									dm->LeftClick();
									Sleep(RandomNumber(180, 220));


									Sleep(RandomNumber(200, 300));
									dm->MoveTo(x + 170, y - 55 - RandomNumber(1, 20));
									Sleep(RandomNumber(1680, 2720));
									strZb = dm->FindPicEx(x - 10, 0, x + 180, 700, L"bagYou.bmp", L"202020", 1, 0);
									arrZb.RemoveAll();
									StringSplit(strZb, arrZb, '|');

									for (size_t i = 0; i < arrJy.GetCount(); i++)
									{
										if (i >= arrZb.GetCount()) {
											break;
										}
										//取装备坐标栏目坐标
										long nX1, nX2, nY1, nY2;
										CString strPoint = arrZb.GetAt(i);
										CStringArray arrPoint;
										StringSplit(strPoint, arrPoint, ',');
										nX1 = _wtoi(arrPoint.GetAt(1));
										nY1 = _wtoi(arrPoint.GetAt(2));
										strPoint = arrJy.GetAt(i);
										arrPoint.RemoveAll();
										StringSplit(strPoint, arrPoint, ',');
										nX2 = _wtoi(arrPoint.GetAt(1));
										nY2 = _wtoi(arrPoint.GetAt(2));
										Sleep(RandomNumber(80, 120));
										dm->MoveToEx(nX1 + 10, nY1 + 10, 5, 10);
										Sleep(RandomNumber(580, 720));
										dm->LeftClick();
										Sleep(RandomNumber(480, 620));
										dm->MoveToEx(nX2 + 10, nY2 + 10, 5, 10);
										Sleep(RandomNumber(580, 620));
										dm->LeftClick();
										Sleep(RandomNumber(1500, 1720));
										//dm->RunScript(L"确定");
										if (dm->RunScript(L"确定")) {
											dm->KeyPress(13);
										}
										Sleep(RandomNumber(580, 620));
									}

									Sleep(RandomNumber(1680, 2720));
								}
							}

							dm->FindPic(0, 0, 1024, 700, L"bagWnd.bmp", L"101010", 1, 0, &x, &y);
							strZb = dm->FindPicEx(x - 70, y, x + 155, y + 300, L"bagYou.bmp", L"202020", 0.9, 0);
							arrZb.RemoveAll();
							StringSplit(strZb, arrZb, '|');
							strJy = dm->FindPicEx(385, 277, 565, 439, L"bagKuang.bmp", L"202020", 1, 0);
							arrJy.RemoveAll();
							StringSplit(strJy, arrJy, '|');

							if (arrZb.GetCount() <= 2) {//装备移动完成执行物品移动
								dm->FindPic(0, 0, 1024, 700, L"bagWnd.bmp", L"101010", 1, 0, &x, &y);
								if (x > 0) {
									dm->MoveToEx(x - 5, y + 23, 5, 5);
									Sleep(RandomNumber(180, 220));
									dm->LeftClick();
									Sleep(RandomNumber(180, 220));
									dm->MoveToEx(x - 40, y - 80, 55, 25);
									Sleep(RandomNumber(80, 120));
									Sleep(RandomNumber(1680, 2720));

									strZb = dm->FindPicEx(x - 100, 0, x + 140, 700, L"mofang.bmp|yaoshui.bmp|card3.bmp|wupinlj.bmp|wupinrj.bmp", L"202020", 1, 0);
									arrZb.RemoveAll();
									StringSplit(strZb, arrZb, '|');
									CString jinbi;
									if (arrJy.GetCount() > 0) {
										int nCount = arrZb.GetCount();
										for (size_t i = 0; i < arrJy.GetCount(); i++)
										{
											if (i >= arrZb.GetCount()) {
												break;
											}
											long nX1, nX2, nY1, nY2;
											CString strPoint = arrZb.GetAt(i);
											CStringArray arrPoint;
											StringSplit(strPoint, arrPoint, ',');
											nX1 = _wtoi(arrPoint.GetAt(1));
											nY1 = _wtoi(arrPoint.GetAt(2));
											strPoint = arrJy.GetAt(i);
											arrPoint.RemoveAll();
											StringSplit(strPoint, arrPoint, ',');
											nX2 = _wtoi(arrPoint.GetAt(1));
											nY2 = _wtoi(arrPoint.GetAt(2));
											Sleep(RandomNumber(80, 120));
											dm->MoveToEx(nX1 + 10, nY1 + 10, 20, 10);
											Sleep(RandomNumber(380, 520));
											dm->LeftClick();
											Sleep(RandomNumber(380, 520));
											dm->MoveToEx(nX2 + 10, nY2 + 10, 20, 10);
											Sleep(RandomNumber(580, 720));
											dm->LeftClick();
											Sleep(RandomNumber(580, 720));
											dm->FindPic(0, 0, 1024, 700, L"inputNum.bmp", L"101010", 1, 0, &x, &y);
											if (x > 0) {
												Sleep(RandomNumber(500, 1000));
												dm->KeyPress(13);
												Sleep(RandomNumber(300, 500));
											}
											Sleep(RandomNumber(1300, 2500));
										}
										//改动
										//strZb = dm->FindPicEx(x - 70, y, x + 140, y + 300, L"card1.bmp|card2.bmp|mofang.bmp", L"202020", 1, 0);
										//arrZb.RemoveAll();
										//StringSplit(strZb, arrZb, '|');
										
									}
									//改动
									dm->FindPic(0, 0, 1024, 700, L"bagWnd.bmp", L"101010", 1, 0, &x, &y);
									strZb = dm->FindPicEx(x - 100, 0, x + 140, 700, L"mofang.bmp|yaoshui.bmp|card3.bmp|wupinlj.bmp|wupinrj.bmp", L"202020", 1, 0);
									arrZb.RemoveAll();
									StringSplit(strZb, arrZb, '|');
									if (arrZb.GetCount() >= 0) {
										dm->FindPic(0, 4, 443, 800, L"bagMoney.bmp", L"202020", 0.8, 0, &x, &y);

										if (x > 0) {//识别金币
											jinbi = dm->Ocr(x + 58, y - 3, x + 145, y + 20, L"000000-050505", 0.9);
											if (_wtoi(jinbi) >= 0) {
												Sleep(2000);
												dm->FindPic(nX - 100, nY, nX, nY + 200, L"yaoshuiTag.bmp", L"101010", 0.9, 0, &x, &y);
												if (x > 0) {
													if (_wtoi(jinbi) > 0) {
														dm->MoveTo(nX + 55, nY + 208);
														dm->LeftClick();
														Sleep(1500);
														//dm->KeyPressStr(L"500", RandomNumber(300, 500));
														dm->SendString2(hwnd, jinbi);
														Sleep(1500);
														dm->KeyPress(13);
														Sleep(2500);
													}
													dm->MoveToEx(nX + 10, nY + 2, 10, 5);
													Sleep(1500);
													dm->LeftClick();
													Sleep(1500);
													for (size_t i = 0; i < 5; i++)
													{
														CString strMap = dm->FindPicS(212, 131, 843, 650, L"yesJy.bmp|JyOk.bmp|jyMan.bmp", L"050505", 1, 0, &x, &y);
														if (strMap != "") {
															if (strMap == L"JyOk.bmp" || strMap == L"jyMan.bmp") {
																dm->KeyPress(13);
																Sleep(1500);
																g_nState = 9;
																int nRoleNum = g_AccountFile.GetInt(NumberToString(taskIndex + 1), L"RoleNum");
																if (jinbi == L"0") {
																	CString strJin = g_AccountFile.GetString(NumberToString(taskIndex + 1), L"bbjb");
																	CString strNoMoney;
																	if (strJin == "") {
																		strNoMoney = NumberToString(nRoleNum); //1
																	}
																	else {
																		strNoMoney = strJin + L"," + NumberToString(nRoleNum);//1,2  1,2,3
																	}
																	//g_AccountFile.SetInt(NumberToString(taskIndex + 1), L"bbjb", nRoleNum);
																	g_AccountFile.SetString(NumberToString(taskIndex + 1), L"bbjb", strNoMoney);
																	g_main_cwnd->m_list_info.SetItemText(taskIndex, 8, strNoMoney);
																}
																++nRoleNum;
																//g_main_cwnd->m_list_info.SetItemText(taskIndex, 6, L"完成");
																//g_AccountFile.SetString(NumberToString(taskIndex + 1), L"state", L"1");
																g_AccountFile.SetInt(NumberToString(taskIndex + 1), L"RoleNum", nRoleNum);
																g_main_cwnd->m_list_info.SetItemText(taskIndex, 7, NumberToString(nRoleNum));
																Sleep(1000);
																return;

															}
															else
															{
																dm->KeyPress(13);
																Sleep(1500);
															}
														}
														Sleep(500);

													}
												}
											}

											//if (jinbi == L"0") {
											//	for (size_t i = 0; i < 5; i++)
											//	{
											//		dm->FindPic(0, 0, 1024, 700, L"jyWndNo.bmp|jyWndNo1.bmp", L"101010", 1, 0, &x, &y);
											//		if (x > 0) {
											//			dm->MoveTo(x + 10 + RandomNumber(1, 33), y + RandomNumber(30, 33));
											//			dm->LeftClick();
											//			Sleep(RandomNumber(100, 200));
											//		}
											//	}
											//	g_nState = 9;
											//	int nRoleNum = g_AccountFile.GetInt(NumberToString(taskIndex + 1), L"RoleNum");
											//	CString strJin = g_AccountFile.GetString(NumberToString(taskIndex + 1), L"bbjb");
											//	CString strNoMoney;
											//	if (strJin == "") {
											//		strNoMoney = NumberToString(nRoleNum); //1
											//	}
											//	else {
											//		strNoMoney = strJin+L","+  NumberToString(nRoleNum);//1,2  1,2,3
											//	}
											//	//g_AccountFile.SetInt(NumberToString(taskIndex + 1), L"bbjb", nRoleNum);
											//	g_AccountFile.SetString(NumberToString(taskIndex + 1), L"bbjb", strNoMoney);
											//	g_main_cwnd->m_list_info.SetItemText(taskIndex, 8, strNoMoney);
											//	++nRoleNum;
											//	//g_main_cwnd->m_list_info.SetItemText(taskIndex, 6, L"完成");
											//	//g_AccountFile.SetString(NumberToString(taskIndex + 1), L"state", L"1");
											//	g_AccountFile.SetInt(NumberToString(taskIndex + 1), L"RoleNum", nRoleNum);
											//	g_main_cwnd->m_list_info.SetItemText(taskIndex, 7, NumberToString(nRoleNum));
											//	
											//	

											//	Sleep(1000);
											//}
										}
									}


								}
							}
						}
					}
					else {
						dm->KeyPress(73);
					}
					
				}
			}
			else {//执行交易动作
				dm->FindPic(16, 493, 347, 685, L"rightWnd.bmp", L"202020", 0.90, 0, &x, &y);
				if (x == -1) {
					dm->MoveTo(171, 618);
					Sleep(RandomNumber(300, 400));
					dm->RightClick();
					Sleep(RandomNumber(500, 600));
				}
				else {
					dm->MoveTo(x + 10, y + 3);
					Sleep(RandomNumber(500, 600));
					dm->LeftClick();
					Sleep(RandomNumber(500, 600));
				}
			}
		}
		Sleep(5000);
	}
	dm->FindPic(0, 0, 1024, 700, L"jyWndNo.bmp|jyWnd.bmp|jyWnd1.bmp|jyWnd2.bmp|jyWndNo1.bmp", L"101010", 1, 0, &x, &y);
	if (x > 0) {
		dm->MoveTo(x + 10 + RandomNumber(1, 33), y + RandomNumber(30, 33));
		dm->LeftClick();
		Sleep(RandomNumber(100, 200));
	}


	//如果交易未开始关闭交易
}

//清理装备
void ClearEquip(long index) {
	CDm *dm = g_info[index].dm;
	long x, y;
	bool bState = false;
	
	for (size_t j = 0; j < 10; j++)
	{
		long nX, nY;
		if (bState) {
			dm->FindPic(0, 0, 900, 500, L"jyBtn.bmp", L"101010", 1, 0, &nX, &nY);
			if (nX > 0) {
				//g/_dm->KeyPress()
				Sleep(1000);
				dm->KeyPress(27);
				Sleep(1000);
			}
			else {
				dm->FindPic(0, 0, 900, 500, L"jyBtn.bmp", L"101010", 1, 0, &nX, &nY);
				if (nX > 0) {
					Sleep(1000);
					dm->KeyPress(27);
					Sleep(1000);
				}
				dm->KeyDown(37);
				for (size_t i = 0; i < 10; i++)
				{
					dm->FindPic(0, 0, 500, 300, L"mapB1.bmp", L"101010", 1, 0, &x, &y);
					if (x > 0) {
						dm->KeyUp(37);
						g_nState = 8;
						Sleep(1000);
						return;

					}
					dm->KeyPress(38);
					Sleep(RandomNumber(80, 120));
				}
				dm->KeyUp(37);
				Sleep(8000);
				dm->FindPic(0, 0, 500, 300, L"mapB1.bmp", L"101010", 1, 0, &x, &y);
				if (x > 0) {
					dm->KeyUp(39);
					g_nState = 8;
					Sleep(1000);
					return;

				}
				dm->KeyDown(39);
				for (size_t i = 0; i < 10; i++)
				{
					dm->FindPic(0, 0, 500, 300, L"mapB1.bmp", L"101010", 1, 0, &x, &y);
					if (x > 0) {
						dm->KeyUp(39);
						g_nState = 8;
						Sleep(1000);
						return;
					}
					dm->KeyPress(38);
					Sleep(RandomNumber(80, 120));
				}
				dm->KeyUp(39);
				Sleep(1000);
			}
		}
		else {
			dm->FindPic(0, 0, 500, 300, L"mapJy.bmp", L"101010", 1, 0, &x, &y);
			if (x > 0) {//进入地图
						//查找npc
				dm->FindPic(0, 0, 900, 500, L"jyBtn.bmp", L"101010", 1, 0, &nX, &nY);
				if (nX > 0) {
					long nRndX = RandomNumber(1, 5);
					long nRndY = RandomNumber(1, 5);
					dm->FindPic(0, 0, 900, 500, L"jyDJ.bmp", L"101010", 0.9, 0, &x, &y);
					if (x > 0) {
						bState = true;
					}

					dm->FindPic(0, 0, 900, 500, L"jyWQ.bmp", L"101010", 1, 0, &x, &y);
					if (x > 0) {//武器已清空
						if (!dm->RunScript(L"物品球")) {
							bState = true;
						}
						dm->FindPic(0, 0, 900, 500, L"jyDJ.bmp", L"101010", 0.9, 0, &x, &y);
						if (x > 0) {
							//int b = 0;
							bState = true;
						}
						else {
							Sleep(RandomNumber(1000, 2000));
							dm->MoveToEx(nX + 250, nY + 98, 5, 5);
							Sleep(RandomNumber(200, 300));
							dm->LeftClick();
							Sleep(RandomNumber(200, 300));
							dm->MoveToEx(nX + 250, nY + 98+100, 15, 150);
							Sleep(RandomNumber(1000, 1300));
							//dm->FindPic(463, 170, 768, 284, L"checkDj.bmp", L"101010", 1, 0, &x, &y);
							dm->RunScript(L"自由市场其他栏", &x, &y);
							if (x > 0) {
								//dm->MoveToEx(nX + 10, nY + 90, 10, 10);
							/*	dm->MoveToEx(nX + 253, nY + 130, 10, 10);
								dm->LeftClick();
								Sleep(RandomNumber(200, 300));
								dm->MoveTo(nX - 200, nY + RandomNumber(300, 400));
								Sleep(RandomNumber(200, 300));*/
								for (size_t i = 0; i <5; i++)
								{
									if (dm->RunScript(L"物品球")) {
										Sleep(RandomNumber(1000, 1500));
										dm->KeyPressChar(L"enter");
										bState = true;
									}
									Sleep(RandomNumber(500, 1000));
									//dm->FindPic(0, 0, 900, 500, L"checkedWP.bmp", L"101010", 1, 0, &x, &y);
									//if (x > 0) {
									//	//dm->MoveTo(nX + 70 + nRndX, nY + 30 + nRndY);
									//	dm->MoveTo(nX + 330 + nRndX, nY + 67 + nRndY);
									//	dm->LeftClick();
									//	Sleep(RandomNumber(1000, 2000));
									//	dm->FindPic(328, 291, 700, 461, L"okWnd2.bmp", L"101010", 1, 0, &x, &y);
									//	if (x > 0) {
									//		dm->MoveToEx(x + 25, y + 58, 5, 5);
									//		dm->LeftClick();
									//		Sleep(RandomNumber(1000, 2000));
									//	}
									//	else {
									//		dm->KeyPress(13);
									//	}
									//}
									//Sleep(100);
								}
							}
						}
					}
					else {//清空武器
						Sleep(RandomNumber(1000, 2000));
						dm->MoveToEx(nX + 253, nY + 138, 10, 10);
						dm->LeftClick();
						Sleep(RandomNumber(200, 300));
						//dm->MoveTo(nX + 10, nY + RandomNumber(300, 400));
						dm->FindPic(463, 170, 768, 284, L"checkDj.bmp", L"101010", 1, 0, &x, &y);
						if (x > 0) {
							dm->Click(nX + 171, nY + 97, 10, 5);
							continue;
						}
						Sleep(RandomNumber(200, 300));
						for (size_t i = 0; i < 20; i++)
						{
							dm->FindPic(0, 0, 900, 500, L"checkedWP.bmp", L"101010", 1, 0, &x, &y);
							if (x > 0) {
								dm->MoveTo(nX + 330 + nRndX, nY + 67 + nRndY);
								dm->LeftClick();
								Sleep(RandomNumber(1000, 2000));
								dm->FindPic(328, 291, 700, 461, L"okWnd2.bmp", L"101010", 1, 0, &x, &y);
								if (x > 0) {
									dm->MoveToEx(x + 25, y + 58, 5, 5);
									dm->LeftClick();
									Sleep(RandomNumber(1000, 2000));
								}
								else {
									dm->KeyPress(13);
								}
							}
							Sleep(100);
						}

					}
				}
				else {
					dm->FindPic(0, 0, 900, 700, L"npcJy.bmp", L"101010", 1, 0, &x, &y);
					if (x > 0) {
						dm->MoveToEx(x + 10, y - 20, 10, 5);
						dm->LeftClick();
					}
				}



			}
			else {
				//打开快速导航
				long x1, y1;
				dm->FindPic(0, 0, 300, 500, L"taskRun.bmp", L"101010", 1, 0, &x, &y);
				if (x > 0) {

					dm->FindPic(0, 0, 1017, 673, L"bagWnd.bmp|bagWnd1.bmp", L"000000", 1, 0, &x1, &y1);
					if (x1>0) {
						dm->KeyPress(73);
						Sleep(1500);
					}

					dm->MoveToEx(x + 10, y + 10, 10, 5);
					dm->LeftClick();
					Sleep(RandomNumber(550, 800));
					dm->MoveToEx(x + 220, y + 300, 10, 35);
					dm->FindPic(0, 0, 700, 600, L"daohang.bmp", L"101010", 1, 0, &x, &y);
					if (x > 0) {
						Sleep(RandomNumber(550, 800));
						dm->MoveToEx(x - 35, y + 104, 10, 5);
						Sleep(RandomNumber(150, 200));
						dm->LeftClick();
						Sleep(RandomNumber(150, 200));
					}

				}
				dm->FindPic(0, 0, 800, 500, L"exitOk.bmp", L"101010", 1, 0, &x, &y);
				if (x > 0) {
					dm->MoveToEx(x + 10, y + 2, 10, 5);
					dm->LeftClick();
					Sleep(RandomNumber(550, 800));
				}

			}
			Sleep(RandomNumber(550, 800));
		}
	}
	dm->FindPic(0, 0, 500, 300, L"mapB1.bmp", L"101010", 1, 0, &x, &y);
	if (x > 0) {
		dm->KeyUp(37);
		g_nState = 8;
		Sleep(1000);
		return;

	}
}

void CloseWnd(long index) {
	dmsoft *dm = g_info[index].dm;
	long x, y;
	dm->FindPic(0, 0, 1024, 768, L"loginOkWnd.bmp|closeWnd.bmp|closeWnd1.bmp|closeWnd4.bmp", L"050505", 1, 0, &x, &y);
	if (x > 0) {
		for (size_t i = 0; i < 10; i++)
		{
			dm->FindPic(0, 0, 1024, 768, L"loginOkWnd.bmp|closeWnd.bmp|closeWnd1.bmp|closeWnd4.bmp", L"050505", 1, 0, &x, &y);
			if (x > 0) {
				dm->MoveTo(x + 5, y + 5);
				Sleep(500);
				dm->LeftClick();
				Sleep(1000);
				dm->MoveTo(x + RandomNumber(300, 400), y + 55);

			}

		}
	}
}

void choseMap(long index,int taskIndex) {
	dmsoft *dm = g_info[index].dm;
	long x, y;
	
	if (g_nState <5) {
		dm->FindPic(0, 0, 500, 300, L"mapJy.bmp", L"101010", 1, 0, &x, &y);
		if (x > 0) {
			dm->KeyDown(37);
			for (size_t i = 0; i < 10; i++)
			{
				dm->FindPic(0, 0, 500, 300, L"mapB1.bmp", L"101010", 1, 0, &x, &y);
				if (x > 0) {
					dm->KeyUp(37);
					g_nState = 8;
					Sleep(1000);
					return;

				}
				dm->KeyPress(38);
				Sleep(RandomNumber(80, 120));
			}
			dm->KeyUp(37);
			dm->FindPic(0, 0, 500, 300, L"mapB1.bmp", L"101010", 1, 0, &x, &y);
			if (x > 0) {
				Sleep(1000);
				return;
			}
			dm->KeyDown(39);
			for (size_t i = 0; i < 10; i++)
			{
				dm->FindPic(0, 0, 500, 300, L"mapB1.bmp", L"101010", 1, 0, &x, &y);
				if (x > 0) {
					dm->KeyUp(39);
					Sleep(1000);
					return;
				}
				dm->KeyPress(38);
				Sleep(RandomNumber(80, 120));
			}
			dm->KeyUp(39);



		}
		dm->FindPic(0, 0, 510, 400, L"mapW.bmp", L"050505", 1, 0, &x, &y);
		if (x > 0) {
			CloseWnd(index);
			dm->KeyDown(37);
			Sleep(2000);
			for (size_t i = 0; i < 20; i++)
			{
				dm->KeyDown(38);
				Sleep(RandomNumber(80, 90));
				dm->KeyUp(38);
			}
			dm->KeyDown(38);
			dm->KeyUp(37);
			dm->KeyUp(38);
			Sleep(5000);
			dm->FindPic(0, 0, 510, 400, L"mapW.bmp", L"050505", 1, 0, &x, &y);
			if (x > 0) {
				dm->KeyDown(39);
				Sleep(1000);
				for (size_t i = 0; i < 10; i++)
				{
					dm->KeyDown(38);
					Sleep(RandomNumber(80, 90));
					dm->KeyUp(38);
				}
				dm->KeyDown(38);
				dm->KeyUp(39);
				dm->KeyUp(38);
			}
		}
	}
	if (g_nState == 0) {



		dm->FindPic(0, 0, 510, 400, L"mapB.bmp", L"050505", 1, 0, &x, &y);
		if (x > 0) {
			dm->KeyPress(38);
		}
		dm->FindPic(0, 0, 283, 227, L"taskRun.bmp|mapB1.bmp", L"050505", 1, 0, &x, &y);
		if (x > 0) {
			dm->FindPic(0, 0, 1000, 700, L"listWnd.bmp", L"050505", 1, 0, &x, &y);
			if (x > 0) {
				dm->MoveTo(x, y + RandomNumber(70, 77));
				dm->LeftDoubleClick();
				Sleep(1000);
				dm->FindPic(0, 0, 1000, 700, L"go.bmp", L"050505", 1, 0, &x, &y);
				if (x > 0) {
					dm->MoveTo(x, y + RandomNumber(3, 5));
					dm->LeftClick();
					Sleep(1000);
					for (size_t i = 0; i < 5; i++)
					{
						dm->FindPic(0, 0, 1000, 700, L"alreadyZhaKun.bmp", L"050505", 1, 0, &x, &y);
						if (x > 0) {
							g_nState = 9;
							int nRoleNum = g_AccountFile.GetInt(NumberToString(taskIndex + 1), L"RoleNum");
							++nRoleNum;
							//g_main_cwnd->m_list_info.SetItemText(taskIndex, 6, L"完成");
							//g_AccountFile.SetString(NumberToString(taskIndex + 1), L"state", L"1");
							g_AccountFile.SetInt(NumberToString(taskIndex + 1), L"RoleNum", nRoleNum);
							g_main_cwnd->m_list_info.SetItemText(taskIndex, 7, NumberToString(nRoleNum));
							return;
						}

						dm->FindPic(0, 0, 1000, 700, L"okWnd.bmp|okWnd1.bmp", L"050505", 1, 0, &x, &y);
						if (x > 0) {
							Sleep(1000);
							dm->MoveTo(x + RandomNumber(3, 5), y + RandomNumber(3, 5));
							Sleep(RandomNumber(500, 1000));
							dm->LeftClick();
							Sleep(2000);
						}
						Sleep(1000);
					}


				}
			}
			else {
				dm->KeyPress(84);
			}

		}
		dm->FindPic(0, 0, 510, 400, L"mapS1.bmp", L"050505", 1, 0, &x, &y);
		if (x > 0) {
			Sleep(2000);
			CloseWnd(index);
			//bool bHuanXian = false;
			for (size_t i = 0; i < 5; i++)
			{
				dm->FindPic(558, 384, 938, 643, L"huanxian.bmp", L"202020", 0.95, 0, &x, &y);
				if (x == -1) {
					dm->KeyPress(27);
					Sleep(RandomNumber(200, 300));
				}
				else {
					Sleep(RandomNumber(200, 300));
					dm->KeyPress(13);
					Sleep(RandomNumber(200, 300));
				}
				dm->FindPic(611, 232, 695, 299, L"xq9.bmp", L"202020", 0.95, 0, &x, &y);
				if (x > 0) {
					Sleep(1000);
					dm->MoveTo(x + 7, y + 5);
					Sleep(500);
					dm->LeftDoubleClick();
					Sleep(500);
					Sleep(8000);
					//n_State = 1;
					break;
				}
				dm->FindPic(611, 232, 695, 299, L"xq91.bmp", L"202020", 0.90, 0, &x, &y);
				if (x > 0) {
					Sleep(1000);
					dm->KeyPress(27);
					Sleep(1000);
					//n_State = 1;
					break;
				}

			}


			dm->FindPic(0, 0, 1000, 700, L"listWnd.bmp", L"050505", 1, 0, &x, &y);
			if (x > 0) {
				dm->KeyPress(84);
			}
			if (movetoX(index,140)) {
				dm->FindPic(0, 0, 1000, 700, L"jiandan.bmp", L"050505", 1, 0, &x, &y);
				if (x > 0) {
					Sleep(1500);
					dm->KeyUp(37);
					dm->KeyUp(39);
					dm->MoveTo(x + 10, y + RandomNumber(3, 5));
					dm->LeftClick();
					Sleep(RandomNumber(80, 150));
					dm->MoveTo(x + 10, y + RandomNumber(40, 50));
					Sleep(4000);
					return;
				}
				Sleep(2000);
				dm->KeyDown(39);
				Sleep(200);
				for (size_t i = 0; i < 20; i++)
				{
					dm->KeyPress(38);
					Sleep(50);
					dm->FindPic(0, 0, 1000, 700, L"jiandan.bmp", L"050505", 1, 0, &x, &y);
					if (x > 0) {
						break;
					}
				}
				dm->KeyUp(39);
				Sleep(1000);
				dm->FindPic(0, 0, 1000, 700, L"jiandan.bmp", L"050505", 1, 0, &x, &y);
				if (x > 0) {
					Sleep(1500);
					dm->KeyUp(37);
					dm->KeyUp(39);
					dm->MoveTo(x + 10, y + RandomNumber(3, 5));
					dm->LeftClick();
					Sleep(RandomNumber(80, 150));
					dm->MoveTo(x + 10, y + RandomNumber(40, 50));
					Sleep(4000);
					return;
				}
				else {
					dm->KeyUp(39);
					dm->KeyDown(37);
					Sleep(RandomNumber(500, 1000));
					for (size_t i = 0; i < 20; i++)
					{
						dm->FindPic(0, 0, 1000, 700, L"jiandan.bmp", L"050505", 1, 0, &x, &y);
						if (x > 0) {
							break;
						}
						dm->KeyPress(38);
						Sleep(50);
					}
					dm->KeyUp(37);
				}
			}
			Sleep(2000);
		}
		dm->FindPic(0, 0, 510, 400, L"mapS2.bmp", L"050505", 1, 0, &x, &y);
		if (x > 0) {
			CString strTeam;
			//取消组队
			for (size_t i = 0; i < 5; i++)
			{
				strTeam = dm->FindPicEx(593, 180, 1022, 705, L"teamXue.bmp", L"050505", 1, 0);
				if (strTeam == L"" || strTeam.Find(L"|")>0) {
					dm->FindPic(37, 167, 1005, 424, L"teamList.bmp", L"101010", 1, 0, &x, &y);
					if (x > 0) {//组队列表已打开
						dm->FindPic(37, 167, 1005, 824, L"exitTeam.bmp", L"101010", 1, 0, &x, &y);
						if (x > 0) {
							dm->MoveToEx(x, y, 10, 10);
							dm->LeftClick();
							Sleep(RandomNumber(100, 150));
							dm->MoveToEx(x + 100, y + 100, 100, 100);
						}
						Sleep(RandomNumber(1000, 1500));
						dm->FindPic(37, 167, 1005, 824, L"addTeam.bmp", L"101010", 1, 0, &x, &y);
						if (x > 0) {
							dm->MoveToEx(x, y, 10, 10);
							dm->LeftClick();
							Sleep(RandomNumber(100, 150));

						}
						Sleep(RandomNumber(1000, 1500));
						dm->FindPic(37, 167, 1005, 624, L"teamOk.bmp", L"101010", 1, 0, &x, &y);
						if (x > 0) {
							dm->MoveToEx(x, y, 10, 10);
							dm->LeftClick();
							Sleep(RandomNumber(100, 150));
						}

					}
					else {
						dm->KeyPress(80);
						Sleep(RandomNumber(1000, 1500));
					}
					Sleep(RandomNumber(1000, 1500));
				}
			}

			dm->FindPic(37, 167, 1005, 424, L"teamList.bmp", L"101010", 1, 0, &x, &y);
			if (x > 0) {
				dm->KeyPress(80);
				Sleep(RandomNumber(100, 150));
			}
			for (size_t ii = 0; ii < 10; ii++)
			{
				dm->FindPic(0, 0, 1024, 700, L"npcS1.bmp", L"050505", 0.9, 0, &x, &y);
				if (x > 0) {
					dm->MoveTo(x + 10, y - RandomNumber(8, 10));
					dm->LeftClick();
					Sleep(RandomNumber(500, 1000));
					dm->MoveTo(x - 100, y);
					for (size_t i = 0; i < 10; i++)
					{
						dm->FindPic(0, 0, 1024, 700, L"next.bmp", L"050505", 1, 0, &x, &y);
						if (x > 0) {
							dm->FindPic(0, 0, 1024, 700, L"exitZha.bmp", L"050505", 1, 0, &x, &y);
							if (x > 0) {
								g_nState = 9;
								int nRoleNum = g_AccountFile.GetInt(NumberToString(taskIndex + 1), L"RoleNum");
								++nRoleNum;
								//g_main_cwnd->m_list_info.SetItemText(taskIndex, 6, L"完成");
								//g_AccountFile.SetString(NumberToString(taskIndex + 1), L"state", L"1");
								g_AccountFile.SetInt(NumberToString(taskIndex + 1), L"RoleNum", nRoleNum);
								g_main_cwnd->m_list_info.SetItemText(taskIndex, 7, NumberToString(nRoleNum));
								Sleep(RandomNumber(4000, 5000));
								return;
							}
							dm->KeyPress(32);
							Sleep(RandomNumber(800,1000));
						}
						Sleep(100);
					}
					dm->MoveTo(x - 100, y - 200);
					break;
				}
			}

		}


	}
	if (g_nState == 6) {
		long x1, y1;
		dm->FindPic(0, 0, 1017, 673, L"bagWnd.bmp|bagWnd1.bmp", L"000000", 1, 0, &x1, &y1);
		if (x1>0) {
			dm->KeyPress(73);
			Sleep(1500);
		}

		for (size_t i = 0; i < 2; i++)
		{
			dm->FindPic(639, 375, 791, 466, L"next1.bmp", L"050505", 1, 0, &x, &y);
			if (x > 0) {
				//if (dm->GetColorNum(419, 730, 614, 751, L"000000", 1) >= 100) {
				//	Sleep(4000);
				//}
				//Sleep(RandomNumber(1000, 1100));
				dm->MoveToEx(x, y, 5, 5);
				dm->LeftClick();

				dm->FindPic(0, 0, 483, 427, L"taskRun.bmp|mapB1.bmp", L"050505", 1, 0, &x, &y);
				if (x > 0) {
					g_nState = 7;
					return;
				}
				//dm->KeyPress(32);
				Sleep(RandomNumber(1000, 1100));
			}
			Sleep(100);
		}

		dm->FindPic(0, 0, 283, 227, L"taskRun.bmp|mapB1.bmp", L"050505", 1, 0, &x, &y);
		if (x > 0) {
			g_nState = 7;
			return;
		}

		dm->FindPic(0, 0, 510, 400, L"mapS1.bmp", L"050505", 1, 0, &x, &y);
		if (x > 0) {
			if (movetoX(index,115)) {
				dm->MoveTo(x + 10, y - RandomNumber(20, 30));
				Sleep(1500);

			}
			for (size_t i = 0; i < 5; i++)
			{
				//dm->MoveTo(x + 10, y - RandomNumber(3, 8));

				//Sleep(1000);
				dm->FindPic(0, 0, 1024, 700, L"npcS2.bmp", L"101010", 1, 0, &x, &y);
				if (x > 0) {
					dm->MoveTo(x + 10, y - RandomNumber(20, 30));
					dm->LeftClick();
					Sleep(1500);
					dm->FindPic(0, 0, 1000, 700, L"exitZk.bmp", L"050505", 1, 0, &x, &y);
					if (x > 0) {
						dm->MoveTo(x + 10, y + RandomNumber(3, 8));
						dm->LeftClick();
						Sleep(1000);
						for (size_t k = 0; k < 2; k++)
						{
							dm->FindPic(639, 375, 791, 466, L"next1.bmp", L"050505", 1, 0, &x, &y);
							if (x > 0) {
								dm->MoveToEx(x, y, 5, 5);
								dm->LeftClick();

								dm->FindPic(0, 0, 483, 427, L"taskRun.bmp|mapB1.bmp", L"050505", 1, 0, &x, &y);
								if (x > 0) {
									g_nState = 7;
									return;
								}
								//dm->KeyPress(32);
								Sleep(RandomNumber(1000, 1100));
							}
							Sleep(100);
							dm->FindPic(0, 0, 383, 327, L"taskRun.bmp|mapB1.bmp", L"050505", 1, 0, &x, &y);
							if (x > 0) {
								g_nState = 7;
								return;
							}
						}

					}
				}
			}
		}

	}



}
